#P17022. [ROI 2026 Day2] 广义象棋
[ROI 2026 Day2] 广义象棋
Problem Description
Mikhail decided to learn generalized chess, so he prepared a board of size . He painted the cell in row and column with color .
Since Mikhail is a beginner, he may have painted the board incorrectly. Therefore, some cells on the board may need to be repainted to another color. A board is called properly colored if and only if it satisfies both of the following conditions:
- The board uses at most two different colors in total.
- There are no edge-adjacent cells with the same color.
Mikhail also considers that playing on a board that is too large would be too difficult. Therefore, he may cut out a smaller board from his board, that is, keep the rectangle formed by the first rows and the first columns, and only make this part properly colored.
For every pair (, ), compute the value —the minimum number of cells Mikhail needs to repaint so that the rectangle formed by the first rows and the first columns becomes properly colored.
Input Format
The first line contains an integer (), which denotes the size of the board.
The next lines describe the board: the -th line contains integers (), representing the colors of the cells in row of the board.
Output Format
Output lines, where the -th line should contain integers .
2
7 7
7 7
0 1
1 2
3
1 1 2
2 4 4
3 1 2
0 1 1
0 2 4
1 3 5
Hint
Subtasks
| Subtask | Score | Dependencies | ||
|---|---|---|---|---|
| 1 | 11 | -- | ||
| 2 | 22 | 1 | ||
| 3 | 8 | -- | -- | |
| 4 | 17 | 3 | ||
| 5 | 15 | 3–4 | ||
| 6 | 7 | 3–5 | ||
| 7 | 20 | -- | 1–6 |
Translated by DeepSeek V4 Pro.
Translated by ChatGPT 5