102951: [Atcoder]ABC295 B - Bombs

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:11 Solved:0

Description

Score : $200$ points

Problem Statement

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}$

Output

Print $R$ lines representing the board after the explosions. Use the format used in the input (do not print $R$ or $C$).


Sample Input 1

4 4
.1.#
###.
.#2.
#.##

Sample Output 1

...#
#...
....
#...

Figure representing the explosion ranges of bombs

  • 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.


Sample Input 2

2 5
..#.#
###.#

Sample Output 2

..#.#
###.#

There may be no bombs.


Sample Input 3

2 3
11#
###

Sample Output 3

...
..#

Sample Input 4

4 6
#.#3#.
###.#.
##.###
#1..#.

Sample Output 4

......
#.....
#....#
....#.

Input

题意翻译

### 题目描述 有一个 $R$ 行 $C$ 列的盘面,点 $(i, j)$ 表示第 $i$ 行第 $j$ 列的格子。上面有三种状态,`.` 代表空地,`#` 代表一堵墙,`1`, `2`, `3` ... `9` 代表炸弹。上面的 `1` ~ `9` 代表炸弹的威力值。 下面,所有的炸弹**同时爆炸**,所有曼哈顿距离小于等于每个点上的威力值的墙将变成空地。 注意:如果该点在爆炸范围内,且该点是炸弹,则不会变成空地。爆炸后,该炸弹本身会变成空地。 你需要输出爆炸后的盘面。 ### 输入格式 第一行,两个数字,代表 $R$ 和 $C$。 接下来 $R$ 行,代表盘面的每一行。 ### 输出格式 $R$ 行,爆炸后的盘面。 ### 数据规模与约定 - $1 \le R, C \le 20$ - $R, C$ 均为整数 - 每个地方只能是 `.`, `#`, `1`, `2`, `3` ... `9` 的字符

Output

得分:200分 部分 问题描述 我们有一个水平方向有R行、垂直方向有C列的棋盘。让$(i,j)$表示从上数第i行、从左数第j列的方格。 你将得到一个字符数组$B_{i,j}$,表示$(i,j)$当前的状态。`.`表示一个空方格;`#`表示一个有墙的方格;`1`、`2`、$\dots$、`9`分别表示一个有爆炸力1、2、$\dots$、9的炸弹的方格。 下一刻,所有的炸弹将会同时爆炸。当一个炸弹爆炸时,所有与该炸弹的曼哈顿距离不大于该炸弹爆炸力的方格将会变成一个空方格。这里,从$(r_1,c_1)$到$(r_2,c_2)$的曼哈顿距离为$|r_1-r_2|+|c_1-c_2|$。 输出爆炸后的棋盘。 部分 限制条件 * $1\leq R,C \leq 20$ * $R$和$C$为整数。 * 每个$B_{i,j}$为`.`、`#`、`1`、`2`、$\dots$、`9`之一。 输入 输入格式如下: ``` $R$ $C$ $B_{1,1}B_{1,2}\dots B_{1,C}$ $\vdots$ $B_{R,1}B_{R,2}\dots B_{R,C}$ ``` 输出 输出爆炸后的棋盘。使用输入中使用的格式(不要打印$R$或$C$)。 样例输入1 ``` 4 4 .1.# ###. .#2. #.## ``` 样例输出1 ``` ...# #... ..... #... ``` 图像解释:爆炸范围示意图 * $(1,2)$处的炸弹爆炸将会将上图中的蓝色方格和紫色方格变为空方格。 * $(3,3)$处的炸弹爆炸将会将上图中的红色方格和紫色方格变为空方格。 在这个样例中,炸弹的爆炸范围可能会重叠。 样例输入2 ``` 2 5 ..#.# ###.# ``` 样例输出2 ``` ..#.# ###.# ``` 可能会没有炸弹。 样例输入3 ``` 2 3 11# ###

HINT

数字是炸弹,曼哈顿距离不超过该数字的位置会被炸开成点,最终效果是?

加入题单

算法标签: