# [zjoi2007]棋盘制作（洛谷1169）

Posted by yjjr's blog on February 6, 2018

# 标签：悬线法，DP

## 输入输出样例

3 3
1 0 1
0 1 0
1 0 0

4
6

## 说明

Code

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define LL long long
#define reg(x) for(int i=last[x];i;i=e[i].to)
using namespace std;
const int maxn=2006;
int n,m,a[maxn][maxn],h[maxn][maxn],l[maxn][maxn];
int r[maxn][maxn],ans1=0,ans2=0;

int main()
{
scanf("%d%d",&n,&m);
rep(i,1,n)
rep(j,1,m){
scanf("%d",&a[i][j]);
if(i==1)h[i][j]=1;
else if(a[i][j]!=a[i-1][j])h[i][j]=h[i-1][j]+1;
else h[i][j]=1;
}
rep(i,1,n){
rep(j,1,m){
l[i][j]=j;
while(l[i][j]>1&&h[i][l[i][j]-1]>=h[i][j]&&a[i][l[i][j]]!=a[i][l[i][j]-1])
l[i][j]=l[i][l[i][j]-1];
}
dep(j,m,1){
r[i][j]=j;
while(r[i][j]<n&&h[i][r[i][j]+1]>=h[i][j]&&a[i][r[i][j]]!=a[i][r[i][j]+1])
r[i][j]=r[i][r[i][j]+1];
}
rep(j,1,m){
int temp=r[i][j]-l[i][j]+1;
ans2=max(ans2,temp*h[i][j]);
ans1=max(ans1,min(temp,h[i][j])*min(temp,h[i][j]));
}
}
printf("%d\n%d\n",ans1,ans2);
return 0;
}