#P6566. [NOI Online #3 入门组] 观星
[NOI Online #3 入门组] 观星
Background
One set of testdata is hand-made. Hacks are welcome.
Problem Description
Jimmy and Symbol agreed to watch the stars together. The vast starry sky can be seen as a matrix with length and width . There are positions in the matrix. A position can be represented by coordinates (, ). Each position may be empty, or may contain a star.
For a position , the adjacent positions are the 8 positions: left, upper-left, up, upper-right, right, lower-right, down, and lower-left. Stars on adjacent positions are considered to belong to the same constellation. This relationship is transitive. For example, if positions , , and all contain stars, then these three stars are considered to be in the same constellation. Constellations with the same number of stars are considered to be in the same galaxy (constellations in the same galaxy do not have to be adjacent). The size of a galaxy is the total number of stars contained in that galaxy.
Since Symbol likes galaxies very much, he wants to test Jimmy by asking him to find how many galaxies there are in the starry sky, and also how large the largest galaxy is.
Input Format
The first line contains two integers representing the length and width of the matrix.
Next, there are lines, each containing characters. Each character is either . or *. In these lines, the -th character of the -th line is * if there is a star at position ; otherwise, it is empty.
Output Format
Output a single line with two integers, separated by a space, representing the number of galaxies and the size of the largest galaxy, respectively.
5 7
*......
..**..*
.*...*.
...*...
....*..
3 4
10 10
**..**.**.
***....*..
*...**.**.
...*..*...
..........
**...**.*.
..*.*....*
..........
***..*.*..
.***..*...
4 12
Hint
For of the testdata, , and the maximum galaxy size does not exceed 200.
For of the testdata, .
For of the testdata, .
For of the testdata, , and the maximum galaxy size does not exceed 100000.
Translated by ChatGPT 5