显示代码纯文本
#include<bits/stdc++.h>
#define re register
using namespace std;
const int maxn=2005;
int ans1,ans2,ch[maxn][maxn],l[maxn][maxn],r[maxn][maxn],up[maxn][maxn];
int main(){
freopen("makechess.in","r",stdin);
freopen("makechess.out","w",stdout);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>ch[i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
l[i][j]=r[i][j]=j,up[i][j]=1;
for(int i=1;i<=n;i++)
for(int j=2;j<=m;j++)
if(ch[i][j]!=ch[i][j-1])
l[i][j]=l[i][j-1];
for(int i=1;i<=n;i++)
for(int j=m-1;j>=1;j--)
if(ch[i][j]!=ch[i][j+1])
r[i][j]=r[i][j+1];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(i>1&&ch[i][j]!=ch[i-1][j]){
l[i][j]=max(l[i][j],l[i-1][j]);
r[i][j]=min(r[i][j],r[i-1][j]);
up[i][j]=up[i-1][j]+1;}
int kkk=min(up[i][j],r[i][j]-l[i][j]+1);
ans1=max(ans1,kkk*kkk);
ans2=max(ans2,up[i][j]*(r[i][j]-l[i][j]+1));
}cout<<ans1<<endl<<ans2;
return 0;
}