#P9582. 「MXOI Round 1」方格

    ID: 10722 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟洛谷原创O2优化排序洛谷月赛

「MXOI Round 1」方格

Problem Description

Xiao C and the grid are good friends.

Xiao C has a grid with nn rows and mm columns. Each cell contains a number, and the number in the cell at row ii and column jj is ai,ja_{i,j}.

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 n,mn,m.

The next nn lines each contain mm integers, where the jj-th integer in the ii-th line represents ai,ja_{i,j}.

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 11 column 11 has 33 good friends, the cell in row 11 column 22 has 22 good friends, the cell in row 11 column 33 has 11 good friend, and the cell in row 11 column 44 has 00 good friends.

The cell in row 22 column 11 has 11 good friend, the cell in row 22 column 22 has 22 good friends, the cell in row 22 column 33 has 11 good friend, and the cell in row 22 column 44 has 11 good friend.

The cell in row 33 column 11 has 11 good friend, the cell in row 33 column 22 has 33 good friends, the cell in row 33 column 33 has 11 good friend, and the cell in row 33 column 44 has 44 good friends.

The total sum of the number of good friends over all cells is 2020.

Sample #2

See square/square2.in and square/square2.ans in the additional files.

This sample satisfies the constraints of test point 11.

Sample #3

See square/square3.in and square/square3.ans in the additional files.

This sample satisfies the constraints of test point 44.

Sample #4

See square/square4.in and square/square4.ans in the additional files.

This sample satisfies the constraints of test point 66.

Sample #5

See square/square5.in and square/square5.ans in the additional files.

This sample satisfies the constraints of test point 1010.

Constraints

For 100%100\% of the testdata, 1n,m20001 \le n,m \le 2000, and 1ai,j91 \le a_{i,j} \le 9.

Test Point n,mn,m \le ai,ja_{i,j} \le Special Property
131\sim3 8080 99 No
454\sim5 20002000 11
676\sim7 99 Yes
8108\sim10 No

Special property: It is guaranteed that the numbers in any two adjacent cells are different.

Translated by ChatGPT 5