#t141. 二阶矩阵
二阶矩阵
Good 2×2 Submatrices
Problem Description
Little A has an matrix .
Little A calls a matrix good if and only if , where denotes the element in the -th row and -th column of .
Little A wants to know how many good submatrices contains.
Input Format
The first line contains two positive integers and . The next lines each contain integers .
Output Format
One line: one integer, the number of good submatrices in .
Sample Input
3 4
1 2 1 0
2 4 2 1
0 3 3 0
Sample Output
2
Sample Explanation
In the given matrix, there are possible submatrices. We check each against .
- The submatrix with top-left corner at row , column is ; we get and , equal, so it is good.
- The submatrix with top-left corner at row , column is ; we get and , equal, so it is also good.
The other four submatrices fail the equality condition, so there are good submatrices in total.
Constraints
For all test points, , , .