继续悬线法
CODE:
#include<iostream>
#include<cstdio>
using namespace std;
int n, m, f[1001][1001], ans2, ans1, l[1001][1001], r[1001][1001];
int h[1001][1001];
int main(){
scanf("%d%d", &n, &m);
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++){
scanf("%d", &f[i][j]);
l[i][j]=r[i][j]=j;
h[i][j]=1;
}
for(int i=1; i<=n; i++){
for(int j=2; j<=m; j++)
if(f[i][j]!=f[i][j-1]) l[i][j]=l[i][j-1];
for(int j=m-1; j>0; j--)
if(f[i][j]!=f[i][j+1]) r[i][j]=r[i][j+1];
}
for(int i=1; i<=m+1; i++)
r[0][i]=m+1;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
if(i>1&&f[i][j]!=f[i-1][j]){
h[i][j]=h[i-1][j]+1;
l[i][j]=max(l[i][j], l[i-1][j]);
r[i][j]=min(r[i][j], r[i-1][j]);
int zfx=min(r[i][j]-l[i][j]+1, h[i][j]);
ans1=max(ans1, (r[i][j]-l[i][j]+1)*h[i][j]);
ans2=max(ans2, zfx*zfx);
}
printf("%d
%d", ans2, ans1);
return 0;
}