atcoder#ABC295B. [ABC295B] Bombs
[ABC295B] Bombs
Score : points
Problem Statement
We have a board with rows running horizontally and columns running vertically. Let denote the square at the -th row from the top and -th column from the left.
You are given characters representing the current states of .
.
represents an empty square; #
represents a square with a wall; 1
, 2
,, 9
represent a square with a bomb of power , respectively.
At the next moment, all bombs will explode simultaneously. When a bomb explodes, every square whose Manhattan distance from the square with the bomb is not greater than the power of the bomb will turn into an empty square. Here, the Manhattan distance from to is .
Print the board after the explosions.
Constraints
- and are integers.
- Each is one of
.
,#
,1
,2
, ,9
.
Input
The input is given from Standard Input in the following format:
Output
Print lines representing the board after the explosions. Use the format used in the input (do not print or ).
4 4
.1.#
###.
.#2.
#.##
...#
#...
....
#...
- The explosion of the bomb at will turn the blue squares and purple squares in the above figure into empty squares.
- The explosion of the bomb at will turn the red squares and purple squares in the above figure into empty squares.
As seen in this sample, the explosion ranges of bombs may overlap.
2 5
..#.#
###.#
..#.#
###.#
There may be no bombs.
2 3
11#
###
...
..#
4 6
#.#3#.
###.#.
##.###
#1..#.
......
#.....
#....#
....#.