Baltic OI '10 P6 - Mines

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type
Baltic Olympiad in Informatics: 2010 Day 2, Problem 3

Heino drew an H \times W grid. Each cell was either empty or contained a mine. Indrek, a good friend of Heino, drew another H \times W grid. In each cell of his grid, he wrote the total number of mines in the corresponding cell of Heino's grid and all its adjacent cells (two cells are adjacent if they share a common point). Indrek then erased Heino's grid. Given Indrek's grid, your task is to help Heino restore his original grid.

You may assume that at least one solution always exists.

Constraints

1 \le H, W \le 600

H \not\equiv 2 \bmod 3 or W \not\equiv 2 \bmod 3

Input Specification

The first line of the input file contains two integers: H, the height of the grid, and W, the width of the grid. The following H lines each contain W digits that describe Indrek's grid.

Output Specification

Output H lines. Each of these lines should contain W characters: X for a mine and . for an empty cell. If there are several correct solutions, output any one of them.

Sample Input

3 5
24531
46631
34310

Sample Output

.XXX.
.XX..
XX...

Comments

There are no comments at the moment.