QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100

#15124. 移动石子

统计

给你一个 $n \times n$ 的网格。每个格子最初包含若干个石头,使得石头的总数恰好为 $n^2$。

在一次操作中,你可以选择一个石头并将其移动到同一行或同一列的任何其他格子中。

你的目标是最小化使每个格子恰好包含一个石头所需的最少操作次数。

输入格式

第一行包含一个整数 $n$,表示网格的大小。

接下来的 $n$ 行,其中第 $i$ 行包含 $n$ 个整数,第 $j$ 个整数 $a_{i,j}$ 表示格子 $(i, j)$ 中的石头数量。

输出格式

输出一个整数,表示使每个格子恰好包含一个石头所需的最少操作次数。

数据范围

  • $1 \le n \le 500$
  • $0 \le a_{i,j} \le n^2$
  • 初始石头总数恰好等于棋盘上的格子总数。

样例

输入样例 1

3
0 1 2
0 2 2
1 1 0

输出样例 1

3

输入样例 2

5
1 2 4 0 1
2 0 0 2 0
1 4 1 0 1
2 0 0 0 0
1 2 0 1 0

输出样例 2

11

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.