#P1162. 填涂颜色
填涂颜色
Description
In a square grid consisting of digits , there is a closed loop formed by digits of arbitrary shape. The task is to fill all spaces inside the closed loop with . For example: for a grid (), the grids before and after filling are as follows:
If starting from some , moving only in the directions up, down, left, and right, and passing only through other s, it is impossible to reach the boundary of the grid, then this is considered to be inside the closed loop. The closed loop is not necessarily ring-shaped; it can be any shape, but it is guaranteed that the s inside the closed loop are connected (any two can reach each other).
0 0 0 0 0 0
0 0 0 1 1 1
0 1 1 0 0 1
1 1 0 0 0 1
1 0 0 1 0 1
1 1 1 1 1 1
0 0 0 0 0 0
0 0 0 1 1 1
0 1 1 2 2 1
1 1 2 2 2 1
1 2 2 1 2 1
1 1 1 1 1 1
Input Format
For each test case, the first line contains an integer ().
The next lines contain an grid consisting of digits and .
There is exactly one closed loop in the grid, and there is at least one inside the loop.
Output Format
Output the complete grid after filling the inside of the closed loop with the digit .
6
0 0 0 0 0 0
0 0 1 1 1 1
0 1 1 0 0 1
1 1 0 0 0 1
1 0 0 0 0 1
1 1 1 1 1 1
0 0 0 0 0 0
0 0 1 1 1 1
0 1 1 2 2 1
1 1 2 2 2 1
1 2 2 2 2 1
1 1 1 1 1 1
Hint
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号