# 悬线法 || BZOJ 1057: [ZJOI2007]棋盘制作 || Luogu P1169 [ZJOI2007]棋盘制作

 1 #include<cstdio>
2 #include<cstring>
3 #include<iostream>
4 #define min(a,b) ((a)<(b)?(a):(b))
5 #define max(a,b) ((a)>(b)?(a):(b))
6 using namespace std;
7 inline int rd(){
8     int x=0,f=1;char c=getchar();
9     while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
10     while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
11     return f*x;
12 }
13 const int maxn=2050,maxm=maxn;
14 int N,M,C[maxn][maxm],H[maxn][maxm],L[maxn][maxm],R[maxn][maxm],ans1=1,ans2=1,w;
15 int main(){
16     N=rd();M=rd();
17     for(int i=1;i<=N;i++)
18         for(int j=1;j<=M;j++)
19             C[i][j]=rd();
20     for(int i=1;i<=N;i++)
21         for(int j=1;j<=M;j++){
22             if(i==1||C[i][j]!=C[i-1][j])
23                 H[i][j]=H[i-1][j]+1;
24             else H[i][j]=1;//H
25             if(j==1||C[i][j]!=C[i][j-1])
26                 L[i][j]=L[i][j-1]+1;
27             else L[i][j]=1;//L
28             int r=M-j+1;
29             if(j==1||C[i][r]!=C[i][r+1])
30                 R[i][r]=R[i][r+1]+1;
31             else R[i][r]=1;
32         }
33     for(int i=1;i<=N;i++)
34         for(int j=1;j<=M;j++){
35             if(H[i][j]>1){
36                 L[i][j]=min(L[i][j],L[i-1][j]);
37                 R[i][j]=min(R[i][j],R[i-1][j]);
38             }
39             w=L[i][j]+R[i][j]-1;
40             ans1=max(ans1,min(w,H[i][j])*min(w,H[i][j]));
41             ans2=max(ans2,w*H[i][j]);
42         }
43     printf("%d\n%d\n",ans1,ans2);
44     return 0;
45 }

By:AlenaNuna

posted @ 2019-03-11 20:32  AlenaNuna  阅读(51)  评论(0编辑  收藏