#P10419. [蓝桥杯 2023 国 A] 01 游戏

    ID: 11937 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2023深度优先搜索 DFS剪枝蓝桥杯国赛

[蓝桥杯 2023 国 A] 01 游戏

Problem Description

Xiao Lan has recently been playing the 0101 game, a board game based on binary ideas. Specifically, the game is played on an N×NN \times N board. Each cell on the board must contain a digit 00 or 11. Initially, some cells already contain fixed digits, and the player is not allowed to change them. The player needs to fill in all other empty cells with digits so that the final board satisfies the following conditions:

  1. All empty cells must be filled with a digit 0/10/1.
  2. In the horizontal or vertical direction, the same digit cannot appear consecutively more than twice.
  3. In each row and each column, the number of 00's and 11's must be equal (for example, when N=4N = 4, each row/column must contain 22 zeros and 22 ones).
  4. Every row must be unique, so no row can be exactly the same as another row. Similarly, every column must be unique, so no column can be exactly the same as another column.

Now please solve the 0101 game together with Xiao Lan! The problem guarantees that every testdata has a unique answer.

Input Format

The first line contains an integer NN, indicating the size of the board.

The next NN lines each contain NN characters. Each character is one of 0, 1, _ (ASCII codes are 4848, 4949, 9595 respectively). 0 means this cell is fixed as 00, 1 means this cell is fixed as 11, and _ means this is an empty cell to be filled by the player.

Output Format

Output NN lines, each containing NN characters, representing the solution. Each character can only be 0 or 1.

6
_0____
____01
__1__1
__1_0_
______
__1___

100110
010101
001011
101100
110010
011001

Hint

[Test Case Scale and Conventions]

For 60%60\% of the test cases, 2N62 \le N \le 6.
For all test cases, 2N102 \le N \le 10, and NN is even.

Thanks to @rui_er for providing the testdata.

Translated by ChatGPT 5