#P6537. [COCI 2013/2014 #1] RATAR
[COCI 2013/2014 #1] RATAR
Problem Description
Given an matrix, determine how many pairs of submatrices have exactly one common vertex and have equal element sums.
Note that the common vertex here means that the two submatrices touch at a corner, not that they share a common cell. Please refer to Sample 1 to understand the meaning of a common vertex.
Input Format
The first line contains a positive integer .
The next lines each contain integers, denoted as , and they may be negative.
Output Format
Output a single line containing the number of valid pairs.
3
1 2 3
2 3 4
3 4 8
7
4
-1 -1 -1 -1
1 2 3 4
1 2 3 4
1 2 3 4
10
5
-1 -1 -1 -1 -1
-2 -2 -2 -2 -2
-3 -3 -3 -3 -3
-4 -4 -4 -4 -4
-5 -5 -5 -5 -5
36
Hint
Constraints
- For of the testdata, .
- For of the testdata, , .
Sample 1 Explanation
The possible rectangle pairs are:
and ;
and ;
and ;
and ;
and ;
and ;
and .
In total there are pairs, so the output is .
Note
Translated from COCI2013-2014 CONTEST #1 T3 RATAR.
is the sample testdata. (10 pts)
In , all testdata satisfy . (30 pts)
In , all testdata satisfy , . Please note the time limit for this subtask. (60 pts)
Translated by ChatGPT 5