#P7410. [USACO21FEB] Just Green Enough S
[USACO21FEB] Just Green Enough S
Problem Description
Farmer John’s pasture can be seen as a square grid made up of square cells (), like a huge chessboard. Because of soil variability, the grass in some cells may be greener. Each cell is described by an integer greenness value , in the range .
Farmer John wants to take a photo of a submatrix of his pasture. He wants to make sure this submatrix looks green enough, but not too green, so he decides to photograph a submatrix whose minimum value of is exactly . Please help him find how many different photos he can take. The largest submatrix can be the entire pasture, and the smallest can be just one cell (there are different submatrices in total—note that this number may not fit in a -bit integer type, so you may need to use a -bit integer type, such as long long in C++).
Input Format
The first line contains . The next lines each contain integers, representing the values of the pasture.
Output Format
Output the number of different photos Farmer John can take, i.e., the number of submatrices whose minimum greenness value is equal to .
Note that the integer size in this problem may require using a -bit integer type (for example, long long in C/C++).
3
57 120 87
200 100 150
2 141 135
8
Hint
Test Point Properties:
- For of the testdata, .
- For the other of the testdata, there are no additional constraints.
Problem by: Brian Dean
Translated by ChatGPT 5