#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 NN and width MM. There are N×MN \times M positions in the matrix. A position can be represented by coordinates (i,j)(i,j) (1iN1 \le i \le N, 1jM1 \le j \le M). Each position may be empty, or may contain a star.

For a position (i,j)(i,j), 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 (1,1)(1,1), (1,2)(1,2), and (1,3)(1,3) 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 N,MN, M representing the length and width of the matrix.

Next, there are NN lines, each containing MM characters. Each character is either . or *. In these NN lines, the jj-th character of the ii-th line is * if there is a star at position (i,j)(i,j); 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 20%20\% of the testdata, N,M20N, M \le 20, and the maximum galaxy size does not exceed 200.

For 50%50\% of the testdata, N,M400N, M \le 400.

For 70%70\% of the testdata, N,M1100N, M \le 1100.

For 100%100\% of the testdata, 2N,M15002 \le N, M \le 1500, and the maximum galaxy size does not exceed 100000.

Translated by ChatGPT 5