#abc099d. D - Good Grid
D - Good Grid
Score : points
问题描述
存在一个包含 行和 列方格的网格。令 表示从上数第 行、从左数第 列的方格。
这些方格需要被涂成从颜色1到颜色 的 种颜色之一。最初, 被涂成了颜色 。
我们称满足以下条件的网格为 好 网格:对于所有满足 的 :
- 如果 ,则 和 的颜色相同。
- 如果 ,则 和 的颜色不同。
此处, 表示 对 取模的结果。
我们需要重新涂色零个或多个方格,使得网格变为一个好网格。
对于一个方格来说,如果在重新涂色前其颜色为 ,重新涂色后颜色为 ,则它的“不匹配度”为 。
求所有方格不匹配度之和的最小可能值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with rows and columns of squares. Let be the square at the -th row from the top and the -th column from the left.
These squares have to be painted in one of the colors from Color to Color . Initially, is painted in Color .
We say the grid is a good grid when the following condition is met for all satisfying :
- If , the color of and the color of are the same.
- If , the color of and the color of are different.
Here, represents modulo .
We will repaint zero or more squares so that the grid will be a good grid.
For a square, the wrongness when the color of the square is before repainting and after repainting, is .
Find the minimum possible sum of the wrongness of all the squares.
Constraints
- $1 \leq D_{i,j} \leq 1000 (i \neq j),D_{i,j}=0 (i=j)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the minimum possible sum of the wrongness of all the squares is , print .
Sample Input 1
2 3
0 1 1
1 0 1
1 4 0
1 2
3 3
Sample Output 1
3
- Repaint to Color . The wrongness of becomes .
- Repaint to Color . The wrongness of becomes .
- Repaint to Color . The wrongness of becomes .
In this case, the sum of the wrongness of all the squares is .
Note that is possible.
Sample Input 2
4 3
0 12 71
81 0 53
14 92 0
1 1 2 1
2 1 1 2
2 2 1 3
1 1 2 2
Sample Output 2
428
update @ 2024/3/10 17:19:34
相关
在下列比赛中: