시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 1024 MB | 231 | 42 | 38 | 21.965% |
In the early 19th century, the ruler Hoseyngulu Khan Sardar ordered a palace to be built on a plateau overseeing a beautiful river. The plateau is modeled as an $n \times m$ grid of square cells. The rows of the grid are numbered $0$ through $n-1$, and the columns are numbered $0$ through $m-1$. We refer to the cell in row $i$ and column $j$ ($0 \leq i \leq n-1, 0 \leq j \leq m-1$) as cell $(i,j)$. Each cell $(i,j)$ has a specific height, denoted by $a[i][j]$.
Hoseyngulu Khan Sardar asked his architects to choose a rectangular area to build the palace. The area should not contain any cell from the grid boundaries (row $0$, row $n-1$, column $0$, and column $m-1$). Hence, the architects should choose four integers $r_1$, $r_2$, $c_1$, and $c_2$ ($1 \leq r_1 \leq r_2 \leq n-2$ and $1 \leq c_1 \leq c_2 \leq m-2$), which define an area consisting of all cells $(i, j)$ such that $r_1 \leq i \leq r_2$ and $c_1 \leq j \leq c_2$.
In addition, an area is considered valid, if and only if for every cell $(i, j)$ in the area, the following condition holds:
The height of cell $(i,j)$ should be strictly smaller than the heights of all these four cells.
Your task is to help the architects find the number of valid areas for the palace (i.e., the number of choices of $r_1$, $r_2$, $c_1$ and $c_2$ that define a valid area).
You should implement the following procedure:
int64 count_rectangles(int[][] a)
Consider the following call.
count_rectangles([[4, 8, 7, 5, 6],
[7, 4, 10, 3, 5],
[9, 7, 20, 14, 2],
[9, 14, 7, 3, 6],
[5, 7, 5, 2, 7],
[4, 5, 13, 5, 6]])
There are $6$ valid areas, listed below:
For example $r_1 = 1, r_2 = 2, c_1 = c_2 = 1$ is a valid area because both following conditions hold:
번호 | 배점 | 제한 |
---|---|---|
1 | 8 | $n, m \leq 30$ |
2 | 7 | $n, m \leq 80$ |
3 | 12 | $n, m \leq 200$ |
4 | 22 | $n, m \leq 700$ |
5 | 10 | $n \leq 3$ |
6 | 13 | $0 \leq a[i][j] \leq 1$ (for all $0 \leq i \leq n-1, 0 \leq j \leq m-1$) |
7 | 28 | No additional constraints. |
Olympiad > International Olympiad in Informatics > IOI 2019 > Day 1 3번
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)