Topic: Given a black and white matrix, the largest black and white sub-squares and sub-matrices
Reverse the point of an odd position, then the largest sub-square and sub-matrix of the solid color
The matrix is divided into layers, above each layer is a similar to the ▆▃▇▂▉, with a monotonous stack run out each point left to right can expand to the maximum distance, update the answer can be
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 2020using namespace Std;int m,n,ans1,ans2;int map[m][m],a[m];void Calculate () {static int stack[m],top;static int Left[m ],right[m];int i;top=0;for (i=1;i<=n+1;i++) {while (top && A[i]<a[stack[top]]) {right[stack[top]]=i; stack[top--]=0;} Stack[++top]=i;} Top=0;for (i=n;~i;i--) {while (top && a[i]<a[stack[top]) {left[stack[top]]=i;stack[top--]=0;} Stack[++top]=i;} for (i=1;i<=n;i++) {int Len=right[i]-left[i]-1;ans1=max (ans1,min (Len,a[i]) *min (Len,a[i])); Ans2=max (ans2,len*a[ I]);}} int main () {int i,j;cin>>m>>n;for (i=1;i<=m;i++) for (j=1;j<=n;j++) {scanf ("%d", &map[i][j]); i+j&1) Map[i][j]^=1;} for (i=1;i<=m;i++) {for (j=1;j<=n;j++) a[j]= (map[i][j]?0:a[j]+1); Calculate ();} memset (a,0,sizeof a); for (i=1;i<=m;i++) for (j=1;j<=n;j++) map[i][j]^=1;for (i=1;i<=m;i++) {for (j=1;j<=n; J + +) a[j]= (map[i][j]?0:a[j]+1); Calculate ();} cout<<ans1<≪endl<<ans2<<endl;return 0;}
Bzoj 1057 ZJOI2007 checkerboard making monotone stack