QOJ.ac

QOJ

Límite de tiempo: 2 s - 30 s Límite de memoria: 2048 MB Puntuación total: 100 Dificultad: [mostrar]

#18226. Number Du Du Du Du Du

Estadísticas

A Sudoku puzzle generally consists of $n$ blocks of size $\sqrt{n} \times \sqrt{n}$ in an $n \times n$ grid.

Each row and each column must contain the numbers $1 \sim n$, with no omissions and no repetitions. Each block (the region enclosed by thick black lines, typically $\sqrt{n} \times \sqrt{n}$) must also contain the numbers $1 \sim n$, with no omissions and no repetitions. A completed puzzle must satisfy all three conditions simultaneously.

The figure above shows an example of an $n \times n$ Sudoku puzzle ($n=9$).

Given an incomplete Sudoku puzzle, you are required to fill in any number of cells such that the completed Sudoku has exactly two solutions. Among all such ways to complete the puzzle, you must choose one where the difference between the two solutions is maximized. Here, the difference is defined as the number of cells where the two solutions contain different digits.

Additionally, for any two positions in the Sudoku, let $x_1, x_2$ be the digits in the two solutions at the first position, and $y_1, y_2$ be the digits in the two solutions at the second position. It is not the case that $x_1 \neq x_2, y_1 \neq y_2, x_1 \neq y_2,$ and $x_1 \neq y_1$ are all satisfied simultaneously.

Input

The first line contains an integer $n$, representing the size of the Sudoku.

The next $n$ lines each contain $n$ integers $a_{i,j}$, representing an incomplete Sudoku puzzle. A value of $0$ indicates an empty cell.

Output

Output $n$ lines, each containing $n$ integers, representing the completed grid. If there are multiple ways to complete the puzzle that satisfy the condition of having exactly two solutions with the maximum possible difference, you may output any one of them.

Examples

Input 1

4
3 0 0 0
0 0 0 0
0 3 0 0
0 0 0 3

Output 1

3 0 0 0
0 0 0 2
0 3 0 0
2 0 0 3

Note

The two solutions corresponding to the sample output are:

3 2 1 4
1 4 3 2
4 3 2 1
2 1 4 3

and:

3 2 4 1
4 1 3 2
1 3 2 4
2 4 1 3

Comparing them cell by cell, the difference is $8$. It can be proven that this is one of the ways to achieve the maximum difference of $8$ for this puzzle.

Data Range

Subtask ID Data Point ID Score Constraints Additional Constraints
1 1 8 $n=4$ None
1 11 8 $n=4$ None
1 12 8 $n=4$ None
1 13 8 $n=4$ None
2 2 6 $n=9$ Initially given $0$ numbers
2 3 6 $n=9$ At most $11$ non-zero numbers given
2 4 6 $n=9$ At most $11$ non-zero numbers given
2 5 6 $n=9$ At most $11$ non-zero numbers given
2 6 6 $n=9$ At most $11$ non-zero numbers given
2 7 6 $n=9$ At most $11$ non-zero numbers given
2 8 6 $n=9$ At most $11$ non-zero numbers given
2 9 6 $n=9$ At most $11$ non-zero numbers given
2 10 6 $n=9$ At most $11$ non-zero numbers given
3 14 7 $n=16$ Initially given $0$ numbers
4 15 7 $n=16$ At most $20$ non-zero numbers given

For all data: $a_{i,j} \in [0, n]$. It is guaranteed that the given incomplete Sudoku puzzle has at least one completion that results in exactly two solutions.

Test Case 14

16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Test Case 15

16
0 0 10 0 0 0 0 1 0 0 0 0 0 0 0 16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 16 0 0 0 0 0 0 0 0 0 0 2 0 0
0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0
0 0 0 0 9 0 0 0 0 0 0 0 0 7 0 0
7 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 15 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 7 0 0 0 0 0 0 0 0 0 0 0 9 0
0 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0
13 0 0 0 0 0 0 0 0 0 8 0 0 0 12 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.