407175: GYM102697 146 Gold Miner
Description
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.
InputThe 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 ".".
OutputOutput $$$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 ".".
ExamplesInput10 .......... ....X..... .......... ..X....X.. .......... .......... ..X....... .......... .......... ..........Output
5432123345 4321X12234 3212122123 21X1221X12 3212332123 3212343234 21X1234345 3212345456 4323456567 5434567678Input
10 .......... .......... .......... .......... .......... .......... .......... .......... .......... .........XOutput
.........9 ........98 .......987 ......9876 .....98765 ....987654 ...9876543 ..98765432 .987654321 987654321X