#P9237. [蓝桥杯 2023 省 A] 像素放置

[蓝桥杯 2023 省 A] 像素放置

Problem Description

Xiao Lan has recently become addicted to a game called "Pixel Placement". The game is played on an n×mn \times m grid board. The board has nn rows, and each row contains mm cells. The player's task is to fill the n×mn \times m cells with pixels, using only two colors: black or white.

Some cells contain an integer digit x(0x9)x(0 \leq x \leq 9). This means that among the 99 cells consisting of this cell plus the eight adjacent cells in the surrounding directions (up, down, left, right, upper-left, upper-right, lower-left, lower-right), there are exactly xx cells that must be filled with black.

The player needs to fill the grid while satisfying all numeric constraints. Please help Xiao Lan complete it. The problem guarantees that a solution exists for all testdata and that the solution is unique.

Input Format

The first line contains two integers n,mn, m, separated by a space, representing the board size.

The next nn lines each contain mm characters, describing the board layout. A character may be a digit 090 \sim 9, meaning a number on the grid. It may also be an underscore (ASCII\text{ASCII} code 9595), meaning a normal cell without a number.

Output Format

Output nn lines, each containing mm characters, representing the answer. If a cell is filled with white, output the character 0. If a cell is filled with black, output the character 1.

6 8
_1__5_1_
1_4__42_
3__6__5_
___56___
_688___4
_____6__
00011000
00111100
01000010
11111111
01011110
01111110

Hint

Sample Explanation

image

In the figure above, the left side is the board layout corresponding to the sample input, and the right side is the solution to that game. For example, the cell at row 33, column 11 contains the number 33. Around it, there are exactly 33 cells filled with black: the cells at row 33, column 22, row 44, column 11, and row 44, column 22.

Constraints

For 50%50\% of the test cases, 1n,m51 \leq n, m \leq 5.

For all test cases, 1n,m101 \leq n, m \leq 10.

Translated by ChatGPT 5