Garden - MarisaOJ: Marisa Online Judge

Garden

Time limit: 1000 ms
Memory limit: 256 MB
Marisa has a garden where she grows herbs, which can be represented as a matrix A of n rows and m columns. The matrix A contains the following characters: - # represents a fence. - . represents an empty plot. - x represents a plant. Two plots belong to the same sector if they are connected by a path that does not run into a fence and consists only of horizontal and vertical steps. Marisa wants to run a statistic on the number of plants in each sector. Count the number of plants in each sector! ### Input - The first line contains 2 integers n,m. - The next n lines, each line contains a string of m characters, Marisa's garden. ### Output - Count the number of plants in each sector and print these numbers in ascending order (ignore sectors with no plant). ### Constraints - 1≤n,m≤103. ### Example Input: 66.....x...x..######..x.#.x...#.×.x#. Output: 25