시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
4 초 | 1024 MB | 21 | 8 | 7 | 50.000% |
JOI-kun is playing on a sand beach. He makes a sandcastle. The sandcastle made by JOI-kun is contained in a rectangular region in the sand beach. The rectangular region consists of cells of $H$ horizontal rows and $W$ vertical columns. The cell in the $i$-th row ($1 ≤ i ≤ H$) from the north and the $j$-th column ($1 ≤ j ≤ W$) from the west has height $A_{i,j}$. Note that the values of $A_{i, j}$ are different from each other.
To the sandcastle, JOI-kun performed the following actions.
Finally, if we view the cells he visited from above, the cells form a rectangle.
Given the information of the height $A_{i, j}$ of each cell, write a program which calculates the number of possible rectangles formed by the the cells JOI-kun visited.
Read the following data from the standard input. Given values are all integers.
$\begin{align*}& H\,W \\ & A_{1,1}\,A_{1,2} \, \cdots \, A_{1,W} \\ & A_{2,1} \, A_{2,2} \, \cdots \, A_{2,W} \\ & \vdots \\ & A_{H,1} \, A_{H,2} \, \cdots \, A_{H,W}\end{align*}$
Write one line to the standard output. The output should contain the number of possible rectangles formed by the cells JOI-kun visited.
번호 | 배점 | 제한 |
---|---|---|
1 | 9 | $H = 1$. |
2 | 10 | $H \times W ≤ 100$. |
3 | 5 | $H \times W ≤ 1\,500$. |
4 | 56 | $H \times W ≤ 7\,000$. |
5 | 20 | No additional constraints. |
1 5 2 4 7 1 5
10
Since there are $10$ possible rectangles formed by the cells JOI-kun visited, output $10$.
This sample input satisfies the constraints of all Subtasks.
3 2 18 10 19 12 17 13
15
Since there are $15$ possible rectangles formed by the cells JOI-kun visited, output $15$.
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5.
3 5 83 47 36 38 40 13 10 26 68 67 15 19 20 70 90
65
For example, the following rectangles can be formed by the cells JOI-kun visited. Since there are $65$ possible rectangles in total, output $65$.
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5.