hdu 1505
City Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2464 Accepted Submission(s): 997
Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you're building stands is 3$.
Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
R – reserved unit
F – free unit
In the end of each area description there is a separating line.
#include<iostream>
using namespace std;
int a[1010][1010],b[1010],d[1010];
int main()
{
int n,m1,m2,sum=0,max,i,j;
while(~scanf("%d",&n))
{
while(n--)
{
scanf("%d%d",&m1,&m2);
memset(a,0,sizeof(a));
for(i=0;i<m1;i++)
{ for(j=0;j<m2;j++) {
char c[2]; scanf("%s",&c);
if(c[0]=='F') a[i][j]=1;
}
}
for(i=1;i<m1;i++)
for(j=0;j<m2;j++)
if(a[i][j]!=0) a[i][j]=a[i-1][j]+1;
max=0;
for(i=0;i<m1;i++)
{
for(j=0;j<m2;j++)
{
b[j]=j;
while(b[j]>0&&a[i][b[j]-1]>=a[i][j]) b[j]=b[b[j]-1];
}
for(j=m2-1;j>-1;j--)
{
d[j]=j;
while(d[j]<m2-1&&a[i][d[j]+1]>=a[i][j]) d[j]=d[d[j]+1];
}
for(j=0;j<m2;j++)
if(max<((d[j]-b[j]+1)*a[i][j])) max=((d[j]-b[j]+1)*a[i][j]);
}
sum=max*3;
printf("%d\n",sum);
}
}
return 0;
}