标签:size pac panel nes algorithm similar acm lin ini
http://acm.hdu.edu.cn/showproblem.php?pid=2870
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include<cstdio> #include<cstring> #include<algorithm> #define N 1001 using namespace std; int n,m,k,minn,ans; char s[N+2][N+2],t[N+2][N+2]; int l[N],r[N]; int a[N],b[N]; int q[N],tmp[N],head,tail; void change(char w,char x,char y,char z) { for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i][j]==x || s[i][j]==y || s[i][j]==z) t[i][j]=w; else t[i][j]=s[i][j]; } void monotonous(int *c,int *d) { int h=1; while(h<=m && !c[h]) h++; if(h>m) return; q[0]=c[h]; tmp[0]=h; head=0; tail=1; for(int i=h+1;i<=m;i++) { if(!c[i]) while(head<tail) d[tmp[head++]]=i-1; else if(head==tail) q[tail]=c[i],tmp[tail++]=i; else { while(head<tail && c[i]<q[tail-1]) d[tmp[--tail]]=i-1; q[tail]=c[i]; tmp[tail++]=i; } } while(head<tail) d[tmp[head++]]=tmp[tail-1]; } void solve(char x) { for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(t[i][j]!=x) a[j]=b[m-j+1]=0; else { if(t[i][j]==t[i-1][j]) a[j]++,b[m-j+1]++; else a[j]=b[m-j+1]=1; } } monotonous(a,r); monotonous(b,l); for(int j=1;j<=m;j++) tmp[j]=l[j]; for(int j=1;j<=m;j++) l[m-j+1]=m-tmp[j]+1; for(int j=1;j<=m;j++) ans=max(ans,(r[j]-l[j]+1)*a[j]); } } int main() { while(scanf("%d%d",&n,&m)!=EOF) { ans=0; for(int i=1;i<=n;i++) scanf("%s",s[i]+1); change(‘a‘,‘w‘,‘y‘,‘z‘); solve(‘a‘); change(‘b‘,‘w‘,‘x‘,‘z‘); solve(‘b‘); change(‘c‘,‘x‘,‘y‘,‘z‘); solve(‘c‘); printf("%d\n",ans); } }
标签:size pac panel nes algorithm similar acm lin ini
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/7308821.html