#C780. Calculate Roof Sliding Heights
Calculate Roof Sliding Heights
Calculate Roof Sliding Heights
You are given a rectangular garden with n rows and m columns. Each cell in the garden is either empty (denoted by '.') or contains a plant (denoted by 'P'). A transparent roof is used to cover the garden from above by sliding downward.
Your task is to determine, for each column, the minimum distance (in number of rows) from the top at which the roof should be positioned so that it covers all the plants in that column. Specifically, for each column, find the first occurrence of a plant when scanning from the top. If a plant is found in row i (1-indexed), then the roof must be slid down to at least row i. If a column contains no plants, the roof will be at the bottom (i.e. at row n).
Note: All formulas are in LaTeX format. For example, if a plant appears in the $i$-th row (from the top), the sliding height for that column is $i$. If there is no plant in a column, then the height is $n$.
inputFormat
The input is read from stdin and has the following format:
$n$ $m$ row1 row2 ... rown
Where:
- $n$ is the number of rows in the garden.
- $m$ is the number of columns in the garden.
- Each of the next $n$ lines contains exactly $m$ characters (either '.' or 'P') representing a row of the garden.
outputFormat
Output to stdout a single line containing $m$ space-separated integers. The $j$-th integer is the minimum height (in rows) the roof must be slid down in the $j$-th column, so that all plants in that column are covered.
## sample5 4
....
.P..
....
..P.
....
5 2 4 5