1.ans=max(全为a的最大矩阵,全为b的最大矩阵,全为c的最大矩阵)
2.代码:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int INF=1<<30; char mat[1005][1005]; int a[1005][1005]; int b[1005][1005]; int c[1005][1005]; int La[1005],Ra[1005]; int Lb[1005],Rb[1005]; int Lc[1005],Rc[1005]; int main() { int m,n; int ans; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); while(scanf("%d%d",&m,&n)==2) { for(int i=1;i<=m;i++) { scanf("%s",mat[i]+1); } ans=-INF; for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(mat[i][j]=='a'||mat[i][j]=='w'||mat[i][j]=='y'||mat[i][j]=='z') a[i][j]=1; else a[i][j]=0; if(mat[i][j]=='b'||mat[i][j]=='w'||mat[i][j]=='x'||mat[i][j]=='z') b[i][j]=1; else b[i][j]=0; if(mat[i][j]=='c'||mat[i][j]=='x'||mat[i][j]=='y'||mat[i][j]=='z') c[i][j]=1; else c[i][j]=0; } } for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(a[i][j]==1) a[i][j]+=a[i-1][j]; if(b[i][j]==1) b[i][j]+=b[i-1][j]; if(c[i][j]==1) c[i][j]+=c[i-1][j]; } for(int j=1;j<=n;j++) { La[j]=j; while(La[j]>1&&a[i][La[j]-1]>=a[i][j]) La[j]=La[La[j]-1]; } for(int j=1;j<=n;j++) { Lb[j]=j; while(Lb[j]>1&&b[i][Lb[j]-1]>=b[i][j]) Lb[j]=Lb[Lb[j]-1]; } for(int j=1;j<=n;j++) { Lc[j]=j; while(Lc[j]>1&&c[i][Lc[j]-1]>=c[i][j]) Lc[j]=Lc[Lc[j]-1]; } for(int j=n;j>=1;j--) { Ra[j]=j; while(Ra[j]<n&&a[i][Ra[j]+1]>=a[i][j]) Ra[j]=Ra[Ra[j]+1]; } for(int j=n;j>=1;j--) { Rb[j]=j; while(Rb[j]<n&&b[i][Rb[j]+1]>=b[i][j]) Rb[j]=Rb[Rb[j]+1]; } for(int j=n;j>=1;j--) { Rc[j]=j; while(Rc[j]<n&&c[i][Rc[j]+1]>=c[i][j]) Rc[j]=Rc[Rc[j]+1]; } for(int j=1;j<=n;j++) { ans=max(ans,a[i][j]*(Ra[j]-La[j]+1)); } for(int j=1;j<=n;j++) { ans=max(ans,b[i][j]*(Rb[j]-Lb[j]+1)); } for(int j=1;j<=n;j++) { ans=max(ans,c[i][j]*(Rc[j]-Lc[j]+1)); } } printf("%d\n",ans); } return 0; }
时间: 2024-11-06 20:29:59