QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#16568. 方格

الإحصائيات

题目描述

小 C 和方格是好朋友。

小 C 有一个 $n$ 行 $m$ 列的方格图,每个方格中都有一个数字,其中第 $i$ 行第 $j$ 列的方格中的数字为 $a_{i,j}$。

我们定义,在这个方格图中,两个不同的方格不相邻,当且仅当这两个方格没有公共边

小 C 认为,两个不同的方格互为好朋友,当且仅当这两个方格不相邻这两个方格中的数字相同

小 C 想让你帮忙求出,所有方格的好朋友的数量之和是多少。

输入格式

第一行两个整数 $n,m$。

接下来 $n$ 行,每行 $m$ 个整数,其中第 $i$ 行的第 $j$ 个整数表示 $a_{i,j}$。

输出格式

一个整数,表示所有方格的好朋友的数量之和。

样例 1 输入

3 4
1 1 4 5
2 1 2 3
3 1 4 1

样例 1 输出

20

样例 1 解释

第 $1$ 行第 $1$ 列的方格共有 $3$ 个好朋友,第 $1$ 行第 $2$ 列的方格共有 $2$ 个好朋友,第 $1$ 行第 $3$ 列的方格共有 $1$ 个好朋友,第 $1$ 行第 $4$ 列的方格共有 $0$ 个好朋友;

第 $2$ 行第 $1$ 列的方格共有 $1$ 个好朋友,第 $2$ 行第 $2$ 列的方格共有 $2$ 个好朋友,第 $2$ 行第 $3$ 列的方格共有 $1$ 个好朋友,第 $2$ 行第 $4$ 列的方格共有 $1$ 个好朋友;

第 $3$ 行第 $1$ 列的方格共有 $1$ 个好朋友,第 $3$ 行第 $2$ 列的方格共有 $3$ 个好朋友,第 $3$ 行第 $3$ 列的方格共有 $1$ 个好朋友,第 $3$ 行第 $4$ 列的方格共有 $4$ 个好朋友;

所有方格的好朋友数量之和为 $20$。

样例 2

见附加文件中的 square/square2.insquare/square2.ans

该样例满足测试点 $1$ 的限制。

样例 3

见附加文件中的 square/square3.insquare/square3.ans

该样例满足测试点 $4$ 的限制。

样例 4

见附加文件中的 square/square4.insquare/square4.ans

该样例满足测试点 $6$ 的限制。

样例 5

见附加文件中的 square/square5.insquare/square5.ans

该样例满足测试点 $10$ 的限制。

数据范围

对于 $100\%$ 的数据,$1 \le n,m \le 2000$,$1 \le a_{i,j} \le 9$。

测试点编号 $n,m \le$ $a_{i,j} \le$ 特殊性质
$1\sim3$ $80$ $9$
$4\sim5$ $2000$ $1$
$6\sim7$ $2000$ $9$
$8\sim10$ $2000$ $9$

特殊性质:保证任意两个相邻的方格中的数不相等。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.