Bombs

AtCoder
IDabc295_b
Time2000ms
Memory256MB
Difficulty
We have a board with $R$ rows running horizontally and $C$ columns running vertically. Let $(i,j)$ denote the square at the $i$\-th row from the top and $j$\-th column from the left. You are given characters $B_{i,j}$ representing the current states of $(i,j)$. `.` represents an empty square; `#` represents a square with a wall; `1`, `2`,$\dots$, `9` represent a square with a bomb of power $1,2,\dots,9$, 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 $(r_1,c_1)$ to $(r_2,c_2)$ is $|r_1-r_2|+|c_1-c_2|$. Print the board after the explosions. ## Constraints * $1\leq R,C \leq 20$ * $R$ and $C$ are integers. * Each $B_{i,j}$ is one of `.`, `#`, `1`, `2`, $\dots$, `9`. ## Input The input is given from Standard Input in the following format: $R$ $C$ $B_{1,1}B_{1,2}\dots B_{1,C}$ $\vdots$ $B_{R,1}B_{R,2}\dots B_{R,C}$ [samples]
Samples
Input #1
4 4
.1.#
###.
.#2.
#.##
Output #1
...#
#...
....
#...

![image](https://img.atcoder.jp/abc295/4816cc7b706b4a095bb9a5d07c614790.jpg)

*   The explosion of the bomb at $(1,2)$ will turn the blue squares and purple squares in the above figure into empty squares.
*   The explosion of the bomb at $(3,3)$ 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.
Input #2
2 5
..#.#
###.#
Output #2
..#.#
###.#

There may be no bombs.
Input #3
2 3
11#
###
Output #3
...
..#
Input #4
4 6
#.#3#.
###.#.
##.###
#1..#.
Output #4
......
#.....
#....#
....#.
API Response (JSON)
{
  "problem": {
    "name": "Bombs",
    "description": {
      "content": "We have a board with $R$ rows running horizontally and $C$ columns running vertically. Let $(i,j)$ denote the square at the $i$\\-th row from the top and $j$\\-th column from the left. You are given cha",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc295_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a board with $R$ rows running horizontally and $C$ columns running vertically. Let $(i,j)$ denote the square at the $i$\\-th row from the top and $j$\\-th column from the left.\nYou are given cha...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments