407175: GYM102697 146 Gold Miner

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

Description

146. Gold Minertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
This problem is worth 40 points.

You're standing in a large 2D grid. The grid consists of several gold blocks. The gold is highly sought after , so for each position in the grid you want to calculate how many steps it would take to walk to the nearest gold block. You can walk left, right, up, or down, but not diagonally.

Input

The first line of input contains a single integer $$$n$$$: the size of the square grid.

The next $$$n$$$ lines each contain $$$n$$$ characters, representing the status of each position in the grid. If the position contains a gold block, it will be represented with an "X". If the position doesn't contain a gold block, it will be represented with a single dot ".".

Output

Output $$$n$$$ lines: the board, after making a few modifications:

Positions with gold blocks should remain an "X".

Positions without gold blocks that are under 10 blocks away from the nearest gold block in walking distance should be represented by their walking distance to the nearest gold block.

Otherwise, positions without gold blocks that are at least 10 blocks away from the nearest gold block in walking distance should remain a single dot ".".

ExamplesInput
10
..........
....X.....
..........
..X....X..
..........
..........
..X.......
..........
..........
..........
Output
5432123345
4321X12234
3212122123
21X1221X12
3212332123
3212343234
21X1234345
3212345456
4323456567
5434567678
Input
10
..........
..........
..........
..........
..........
..........
..........
..........
..........
.........X
Output
.........9
........98
.......987
......9876
.....98765
....987654
...9876543
..98765432
.987654321
987654321X

加入题单

上一题 下一题 算法标签: