#P9582. 「MXOI Round 1」方格
「MXOI Round 1」方格
Problem Description
Xiao C and the grid are good friends.
Xiao C has a grid with rows and columns. Each cell contains a number, and the number in the cell at row and column is .
We define that, in this grid, two different cells are non-adjacent if and only if these two cells do not share a common edge.
Xiao C thinks that two different cells are good friends of each other if and only if these two cells are non-adjacent and the numbers in these two cells are the same.
Xiao C wants you to help compute the total sum of the number of good friends over all cells.
Input Format
The first line contains two integers .
The next lines each contain integers, where the -th integer in the -th line represents .
Output Format
Output one integer, representing the total sum of the number of good friends over all cells.
3 4
1 1 4 5
2 1 2 3
3 1 4 1
20
Hint
Sample Explanation #1
The cell in row column has good friends, the cell in row column has good friends, the cell in row column has good friend, and the cell in row column has good friends.
The cell in row column has good friend, the cell in row column has good friends, the cell in row column has good friend, and the cell in row column has good friend.
The cell in row column has good friend, the cell in row column has good friends, the cell in row column has good friend, and the cell in row column has good friends.
The total sum of the number of good friends over all cells is .
Sample #2
See square/square2.in and square/square2.ans in the additional files.
This sample satisfies the constraints of test point .
Sample #3
See square/square3.in and square/square3.ans in the additional files.
This sample satisfies the constraints of test point .
Sample #4
See square/square4.in and square/square4.ans in the additional files.
This sample satisfies the constraints of test point .
Sample #5
See square/square5.in and square/square5.ans in the additional files.
This sample satisfies the constraints of test point .
Constraints
For of the testdata, , and .
| Test Point | Special Property | ||
|---|---|---|---|
| No | |||
| Yes | |||
| No |
Special property: It is guaranteed that the numbers in any two adjacent cells are different.
Translated by ChatGPT 5