qwqTNTqwq @ 2024-10-19 23:41:28
#include <bits/stdc++.h>
using namespace std;
int a[11][11];
bool check(int x1, int y1, int x2, int y2)
{
int cnt1 = 0, cnt2 = 0;
for (int i = x1; i <= x2; i++)
{
for (int j = y1; j <= y2; j++)
{
if (a[i][j] == 1)
{
cnt1++;
}
else
{
cnt2++;
}
}
}
if (cnt1 == cnt2)
{
return true;
}
else
{
return false;
}
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
string s;
cin >> s;
for (int j = 0; j < m; j++)
{
a[i][j + 1] = s[j] - '0';
}
}
int ans = 0;
for (int x1 = 1; x1 <= n; x1++)
{
for (int y1 = 1; y1 <= m; y1++)
{
for (int x2 = 1; x2 <= n; x2++)
{
for (int y2 = 1; y2 <= m; y2++)
{
if (x1 == x2 && y1 == y2)
{
continue;
}
if (check(x1, y1, x2, y2))
{
ans = max(ans, (x2 - x1 + 1) * (y2 - y1 + 1));
}
}
}
}
}
cout << ans;
return 0;
}
by Nemo114514 @ 2024-10-21 21:49:13
前排智齿 qp
by Genshin_Balladeer @ 2024-10-23 08:25:10
I,J 不应该从 1 开始枚举,要分别从 i,j 开始枚举。如果 I<i 或者 J<j check 函数始终会返回 true,此时如果 (I-i+1)*(J-j+1) 为正数就会统计到错误答案。 @qwqTNTqwq
by Genshin_Balladeer @ 2024-10-23 08:26:26
x2 从 x1 开始, 一 y2 从 y1 开始
by qwqTNTqwq @ 2024-10-25 19:27:48
@Genshin_Balladeer 谢谢大佬