You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1 KiB

2 years ago
#include <bits/stdc++.h>
/*
I
5 6
1 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
4
II
5 6
1 0 1 0 0 0
0 1 0 1 1 0
1 0 0 0 1 0
0 1 0 0 0 1
1 0 1 0 0 0
2
*/
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int a[N][N];
int s[N][N];
int res;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
for (int i = 1; i <= n; i++) // 100
for (int j = 1; j <= m; j++) { // 100
for (int r = 0;; r++) {
if (i + r > n || j + r > m) break; // 越界
if (a[i + r][j + r] == 0) break;
int x1 = i, y1 = j, x2 = i + r, y2 = j + r;
int sum = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
if (sum != r + 1) break;
res = max(res, r + 1);
}
}
printf("%d\n", res);
return 0;
}