#P9237. Pixel Placement Puzzle

    ID: 22392 Type: Default 1000ms 256MiB

Pixel Placement Puzzle

Pixel Placement Puzzle

In this problem, you are given an n×mn \times m grid. Some cells contain a digit xx (0x90 \le x \le 9) which indicates that in the 3×33 \times 3 block centered at that cell (including the cell itself), there must be exactly xx black cells. The other cells do not contain any constraints. Your task is to fill the entire grid with either black ('B') or white ('W') colors such that all given constraints are satisfied. It is guaranteed that there is a unique solution.

inputFormat

The first line contains two integers nn and mm, representing the number of rows and columns of the grid. The following nn lines each contain mm tokens separated by spaces. Each token is either a digit ('0'-'9') indicating a constraint, or a dot ('.') indicating that there is no constraint in that cell.

outputFormat

Output nn lines, each containing mm characters. Each character must be either 'B' (for a black cell) or 'W' (for a white cell). This output grid should satisfy all the constraints given in the input.

sample

4 4
2 . 2 .
. 5 . .
. . 4 .
. . . 2
BWBW

WBWW WBBW WWWB

</p>