#P6083. [JSOI2015] symmetry

    ID: 5062 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2015二分各省省选江苏哈希,HASH

[JSOI2015] symmetry

Description

Mr. Zhang is explaining symmetry patterns of squares in class. For simplicity, he uses a 0101 matrix to represent a square pattern: divide the square into an n×nn\times n grid, where 00 represents a white cell and 11 represents a black cell.

He first talks about easy-to-see reflection symmetry. A square has 44 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 180180 degrees around its center, it is called a 180180-degree symmetric pattern. If it remains unchanged after rotating 9090 degrees clockwise around its center, it is called a 9090-degree symmetric pattern. For example, in the following two patterns, the left one is 180180-degree symmetric, and the right one is 9090-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 44-symmetric pattern; if it is symmetric with respect to all 44 axes, it is called an 88-symmetric pattern. By definition, a 9090-degree symmetric pattern is also a 180180-degree symmetric pattern, and an 88-symmetric pattern is also a 44-symmetric pattern. When the side length of the square pattern is even, its center is the common vertex of the 44 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 11 is obviously an 88-symmetric pattern.

Mr. Zhang proves two theorems to the students.

  • Theorem 11: A square pattern is a 44-symmetric pattern if and only if it is both a 180180-degree symmetric pattern and an axis-symmetric pattern.
  • Theorem 22: A square pattern is an 88-symmetric pattern if and only if it is both a 9090-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 0101 matrix, output the maximum side length of a contiguous square submatrix that satisfies, respectively, 88-symmetry, 9090-degree symmetry, 44-symmetry, 180180-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 nn, the side length of the large square pattern. Then follow nn lines, each a 0101 string of length nn.

Output Format

Output one line containing 55 natural numbers separated by spaces, representing the maximum side length of a contiguous square submatrix appearing in the input that is, respectively, 88-symmetric, 9090-degree symmetric, 44-symmetric, 180180-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 2×22\times 2 88-symmetric pattern in the upper-left corner. The rightmost 33 columns of the middle 33 rows form a 44-symmetric pattern.


Constraints

For 100%100\% of the testdata, 5n5005\leq n\leq 500.

Translated by ChatGPT 5