#P6083. [JSOI2015] symmetry
[JSOI2015] symmetry
Description
Mr. Zhang is explaining symmetry patterns of squares in class. For simplicity, he uses a matrix to represent a square pattern: divide the square into an grid, where represents a white cell and represents a black cell.
He first talks about easy-to-see reflection symmetry. A square has axes of symmetry: the horizontal midline, the vertical midline, and the two diagonals. If a square pattern remains unchanged after reflecting across one symmetry axis, it is called an axis-symmetric pattern. For example, the following two patterns are both axis-symmetric.
100 010
100 101
111 000
Mr. Zhang then explains rotational symmetry of squares. If a square pattern remains unchanged after rotating degrees around its center, it is called a -degree symmetric pattern. If it remains unchanged after rotating degrees clockwise around its center, it is called a -degree symmetric pattern. For example, in the following two patterns, the left one is -degree symmetric, and the right one is -degree symmetric.
0011 1011
1110 1110
0111 0111
1100 1101
Mr. Zhang continues: if a square pattern has two perpendicular axes of symmetry, it is called a -symmetric pattern; if it is symmetric with respect to all axes, it is called an -symmetric pattern. By definition, a -degree symmetric pattern is also a -degree symmetric pattern, and an -symmetric pattern is also a -symmetric pattern. When the side length of the square pattern is even, its center is the common vertex of the middle cells; when the side length is odd, the pattern has a central cell, and the center of the pattern is also the center of that central cell. A pattern of side length is obviously an -symmetric pattern.
Mr. Zhang proves two theorems to the students.
- Theorem : A square pattern is a -symmetric pattern if and only if it is both a -degree symmetric pattern and an axis-symmetric pattern.
- Theorem : A square pattern is an -symmetric pattern if and only if it is both a -degree symmetric pattern and an axis-symmetric pattern.
Finally, it is practice time. Mr. Zhang asks the students to find various symmetric patterns that appear inside a large square pattern. Please write a program to do this. Given a matrix, output the maximum side length of a contiguous square submatrix that satisfies, respectively, -symmetry, -degree symmetry, -symmetry, -degree symmetry, and axis symmetry. A contiguous square submatrix means a submatrix chosen by selecting several adjacent rows and columns, representing a small pattern appearing in the large pattern.
Input Format
The first line contains a positive integer , the side length of the large square pattern. Then follow lines, each a string of length .
Output Format
Output one line containing natural numbers separated by spaces, representing the maximum side length of a contiguous square submatrix appearing in the input that is, respectively, -symmetric, -degree symmetric, -symmetric, -degree symmetric, and axis-symmetric.
5
11100
11000
10111
11000
11100
2 2 3 3 5
Hint
Explanation of the Sample
The large pattern has a horizontal axis of symmetry. There is a -symmetric pattern in the upper-left corner. The rightmost columns of the middle rows form a -symmetric pattern.
Constraints
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号