悬线法,直接做就行,不用取反什么的
小改动:l,r,h 遇到障碍点时赋1不赋0
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 const int N=2001; 5 int c[N][N],l[N][N],r[N][N],h[N][N],n,m; 6 int max(int,int),min(int,int); 7 void begin(); 8 int main(){ 9 int ans1,ans2,x; 10 ans1=ans2=0; 11 scanf("%d %d",&n,&m); 12 for (int i=1;i<=n;i++) 13 for (int j=1;j<=m;j++) 14 scanf("%d",&c[i][j]); 15 begin(); 16 for (int i=1;i<=n;i++) 17 for (int j=1;j<=m;j++){ 18 if (c[i][j]!=c[i][j-1]) 19 l[i][j]=l[i][j-1]+1; 20 else l[i][j]=1; 21 if (c[i][m-j+1]!=c[i][m-j+2]) 22 r[i][m-j+1]=r[i][m-j+2]+1; 23 else r[i][m-j+1]=1; 24 if (c[i][j]!=c[i-1][j]) 25 h[i][j]=h[i-1][j]+1; 26 else h[i][j]=1; 27 28 } 29 for (int i=1;i<=n;i++) 30 for (int j=1;j<=m;j++){ 31 if (h[i][j]>1){ 32 l[i][j]=min(l[i][j],l[i-1][j]); 33 r[i][j]=min(r[i][j],r[i-1][j]); 34 } 35 ans1=max(ans1,h[i][j]*(l[i][j]+r[i][j]-1)); 36 x=min(h[i][j],l[i][j]+r[i][j]-1); 37 ans2=max(ans2,x*x); 38 } 39 printf("%d\n%d",ans2,ans1); 40 return 0; 41 } 42 void begin(){ 43 for (int i=1;i<=n;i++){ 44 c[i][0]=1-c[i][1]; 45 c[i][m+1]=1-c[i][m]; 46 } 47 for (int i=1;i<=m;i++) 48 c[0][i]=1-c[1][i]; 49 } 50 int max(int x,int y){ 51 return x>y?x:y; 52 } 53 int min(int x,int y){ 54 return x<y?x:y; 55 }