#abc295b. B - Bombs

B - Bombs

Score : 200200 points

问题描述

我们有一个棋盘,其横向有 RR 行,纵向有 CC 列。令 (i,j)(i,j) 表示从上数第 ii 行、从左数第 jj 列的方格。

你被赋予了一些字符 Bi,jB_{i,j},它们代表了当前 (i,j)(i,j) 方格的状态。. 表示一个空方格;# 表示一个带有墙壁的方格;1, 2,\dots, 9 分别表示带有威力为 1,2,,91,2,\dots,9 的炸弹的方格。

在下一时刻,所有炸弹将会同时爆炸。当一颗炸弹爆炸时,所有与该炸弹所在方格的曼哈顿距离不大于炸弹威力的方格都将变成空方格。这里,从方格 (r1,c1)(r_1,c_1)(r2,c2)(r_2,c_2) 的曼哈顿距离定义为 r1r2+c1c2|r_1-r_2|+|c_1-c_2|

请打印出爆炸后棋盘的状态。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a board with RR rows running horizontally and CC columns running vertically. Let (i,j)(i,j) denote the square at the ii-th row from the top and jj-th column from the left.

You are given characters Bi,jB_{i,j} representing the current states of (i,j)(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,,91,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 (r1,c1)(r_1,c_1) to (r2,c2)(r_2,c_2) is r1r2+c1c2|r_1-r_2|+|c_1-c_2|.

Print the board after the explosions.

Constraints

  • 1R,C201\leq R,C \leq 20
  • RR and CC are integers.
  • Each Bi,jB_{i,j} is one of ., #, 1, 2, \dots, 9.

Input

The input is given from Standard Input in the following format:

RR CC

B1,1B1,2B1,CB_{1,1}B_{1,2}\dots B_{1,C}

\vdots

BR,1BR,2BR,CB_{R,1}B_{R,2}\dots B_{R,C}

Output

Print RR lines representing the board after the explosions. Use the format used in the input (do not print RR or CC).

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)(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)(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

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

update @ 2024/3/10 12:15:48