#P1681. 最大正方形II
最大正方形II
Background
After finishing his schoolwork, v 神 could finally do his "real business": taking a walk with his girlfriend. One day, as they walked, they unknowingly arrived at a desolate place. Just as v 神 was about to turn back, he noticed a sign. The sign had a line of small text and a picture. The small text said: "Contact me after you find the largest alternating square in the picture, and this land will be yours." In an era of soaring housing prices, v 神 certainly did not want to miss this opportunity, so he started searching... Of course, with v 神's ability, he couldn't find it. Can you help v 神 find it?
Problem Description
There is a grid on the picture, consisting of cells. Each cell is colored either black or white. Find a square of maximum area whose interior is black-and-white alternating, that is, any two adjacent unit cells (sharing an edge) must not have the same color.
Input Format
The first line contains two integers and , denoting the number of rows and columns, respectively. Then follow lines, each containing numbers. Each number is or , indicating that the cell is black or white, respectively.
Output Format
Output a single line containing the side length of the largest square that satisfies the condition.
3 3
0 1 0
1 0 0
1 1 1
2
Hint
Sample Explanation: The square from to satisfies the condition, and its side length is .
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5