#C8495. Max Garden Height
Max Garden Height
Max Garden Height
You are given a garden represented as a grid with R rows and C columns. Each cell of the garden contains either a digit (as a string) representing the initial height of a plant, or a dot .
indicating an empty cell.
A plant at cell (r, c) with height h will spread its growth to any empty cell within a Manhattan distance at most h. Formally, it can spread to any cell (r+dr, c+dc) satisfying \[ |dr|+|dc| \leq h \] provided that the cell is empty. The garden is processed in row‐major order (from the top row to the bottom row, and within each row from left to right). When a plant spreads, the empty cell is updated to carry the same height as the plant.
Your task is to simulate this process and determine the maximum growth height in the garden after all valid spreads have been performed.
Note: Although plants spread to empty cells, this propagation is done in place during the row‐major order scanning. That is, if a cell is updated earlier, it may itself cause further spreads as you continue the scan.
inputFormat
The input is read from standard input (stdin) and has the following format:
R C row1 row2 ... rowR
Here, the first line contains two integers, R and C (the number of rows and columns respectively). Each of the next R lines contains C space-separated tokens. Each token is either a digit (a string representing an integer between 1 and 9) indicating the plant height, or a dot .
representing an empty cell.
outputFormat
Output a single integer to standard output (stdout) representing the maximum height in the garden after simulating the spread of growth from all plants.
Note: The propagation should be simulated as you scan the grid in row‐major order.
## sample3 4
. 3 . .
2 . . .
. . . .
3