Files
python/TangDou/LanQiaoBei/LanQiaoBei13ShengSai_ZJ_II/6_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

55 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}