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
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
In addition, an area is considered valid, if and only if for every cell
- Consider the two cells adjacent to the area in row
(cell and cell ) and the two cells adjacent to the area in column (cell and cell ). The height of cell 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
Implementation details
You should implement the following procedure:
long long count_rectangles(std::vector<std::vector<int>> a)
: a two-dimensional by array of integers representing the heights of the cells.- This procedure should return the number of valid areas for the palace.
Examples
Example 1
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 valid
For example
is strictly smaller than , , , and . is strictly smaller than , , , and .
Constraints
(for all )
Subtasks
- (
points) - (
points) - (
points) - (
points) - (
points) - (
points) (for all ) - (
points) No additional constraints.
Sample grader
The sample grader reads the input in the following format:
- line
: - line
(for ):
The sample grader prints a single line containing the return value of count_rectangles
.
Comments