the main algorithm as the 1506
#include <stdio.h> #include <iostream> #include <string> using namespace std; char gird[1100][1100]; int num[1100][1100]; int m,n; int find(int a){ int i,j,res,max; int t; int l[1100],r[1100]; l[1]=1; r[m]=m; for(i=2;i<=m;++i){ t=i; if(num[a][i]==0){ l[i]=i; continue; } while(t>1&&num[a][i]<=num[a][t-1]) t=l[t-1]; l[i]=t; } for(i=m-1;i>=1;--i){ t=i; if(num[a][i]==0){ r[i]=i; continue; } while(t<m&&num[a][i]<=num[a][t+1]) t=r[t+1]; r[i]=t; } res=0; for(i=1;i<=m;++i){ if( (r[i]-l[i]+1)*3*num[a][i] > res ) res = (r[i]-l[i]+1)*3*num[a][i]; } /* for(i=1;i<=m;++i) cout<<num[a][i]<<" "; cout<<endl; cout<<"left-----"<<endl; for(i=1;i<=m;++i) cout<<l[i]<<" "; cout<<endl; cout<<"right---"<<endl; for(i=1;i<=m;++i) cout<<r[i]<<" "; cout<<endl; cout<<res<<endl; */ return res; } int init(){ cin>>n>>m; int i,j,tmp; for(i=1;i<=n;++i) for(j=1;j<=m;++j) cin>>gird[i][j]; for(j=1;j<=m;++j) if(gird[1][j]=='F') num[1][j]=1; else num[1][j]=0; for(i=2;i<=n;++i) for(j=1;j<=m;++j){ if(gird[i][j]=='F') num[i][j]=num[i-1][j]+1; else num[i][j]=0; } int res=0; for(i=1;i<=n;++i){ tmp=find(i); if(tmp>res) res=tmp; } return res; } int main(){ int t,i,j; while(cin>>t){ while(t--){ cout<<init()<<endl; } } return 0; }