0% found this document useful (0 votes)
1 views2 pages

Problem-K

The problem involves an n x n grid where each cell contains a certain number of stones, totaling n². The objective is to determine the minimum number of moves required to redistribute the stones so that each cell contains exactly one stone, with moves allowed only within the same row or column. The input consists of the grid size and the number of stones in each cell, and the output is a single integer representing the minimum moves needed.

Uploaded by

小何
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Problem-K

The problem involves an n x n grid where each cell contains a certain number of stones, totaling n². The objective is to determine the minimum number of moves required to redistribute the stones so that each cell contains exactly one stone, with moves allowed only within the same row or column. The input consists of the grid size and the number of stones in each cell, and the output is a single integer representing the minimum moves needed.

Uploaded by

小何
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Problem K

Move Stone
Time limit: 1 second

Problem Description
You are given an n → n grid. Each cell initially contains some number of stones, such that the
total number of stones is exactly n2 .
In one move, you may take a single stone and move it to any other cell in the same row or the
same column.
Your goal is to minimize the number of moves needed to make each cell contain exactly one
stone.

Input Format
The first line contains an integer n, representing the size of the grid.
Followed by n lines, the i-th of which contains n integers, the j-th integer ai,j represents the
number of stones in cell (i, j).

Output Format
Output a single integer, the minimum number of moves required to make each cell contain
exactly one stone.

Technical Specification
• 1 ↑ n ↑ 500
• 0 ↑ ai,j ↑ n2
• The initial number of stones is exactly equal to the number of cells on the board.

The 2025 ICPC Asia Taiwan Online Programming Contest Problem K © TCPC 25
Sample Input 1 Sample Output 1
3 3
0 1 2
0 2 2
1 1 0

Sample Input 2 Sample Output 2


5 11
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

The 2025 ICPC Asia Taiwan Online Programming Contest Problem K © TCPC 26

You might also like