P29159 [洛谷] [COCI2008-2009#3] CROSS
普及+
题目描述

Problem Background

In the Sudoku game, the goal is to place the integers from $1$ to $9$ into a $9 \times 9$ grid such that each row, each column, and each of the nine $3 \times 3$ subgrids contain all of the digits from $1$ to $9$ without repetition. The $9 \times 9$ grid is partially filled initially, allowing the values of other cells to be deduced logically.

Sudoku puzzles vary in difficulty, with more challenging puzzles often requiring more complex analytical methods.

Problem Description

In this problem, you need to use the simplest method, known as cross-hatching.

Within the grid, we select one of the nine digits and cross out the corresponding rows, columns, and $3 \times 3$ subgrids where the digit appears. The goal is to find a $3 \times 3$ region where the digit can be placed.

You will be provided with a partially filled grid. Your task is to repeatedly use the cross-hatching method for different digits until no further deductions can be made.

The first image below shows a very sparse Sudoku. However, even with such sparsity, the cross-hatching method can still infer that the top-left cell should be $4$, as shown in the second image.

Additionally, you need to output ERROR in the following cases:
- The initial placement of digits in the grid is invalid.
- The digit cannot be placed in any of the $3 \times 3$ subgrids.

Input Format

The input consists of $9$ lines, each containing $9$ characters. Each character will be a digit from $1$ to $9$ or a . representing an empty cell.

Output Format

If the input is valid and there are no contradictions during solving, output the grid in the same format.

Fill in the cells where the value can be deduced using cross-hatching.

Otherwise, output ERROR.

Sample Input and Output

Sample Input #1

..9......
.....4...
.......4.
.........
.4.......
.........
.........
.........
.........

Sample Output #1

4.9......
.....4...
.......4.
.........
.4.......
.........
.........
.........
.........

Sample Input #2

...1...6.
18...9...
..7.642..
2.9..6.5.
.43...72.
.6.3..9.1
..265.1..
...2...97
.5...3...

Sample Output #2

524137869
186529473
397864215
219476358
843915726
765382941
972658134
638241597
451793682

Sample Input #3

1........
..1......
.......1.
.........
.........
.........
.........
.........
.........

Sample Output #3

ERROR

Sample Input #4

........2
....1....
1........
......1..
.........
.........
.........
.......1.
.........

Sample Output #4

ERROR

Notes

Translated from COCI2008-2009 CONTEST #3 T3 CROSS.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
..9...... .....4... .......4. ......... .4....... ......... ......... ......... .........
样例输出
4.9...... .....4... .......4. ......... .4....... ......... ......... ......... .........