链接
http://www.lydsy.com/JudgeOnline/problem.php?id=3039
题解
fij
表示从这个格子往左数有多少连续的
F
。
ans=max(fij×gij)
代码
//乱搞+单调栈
#include <cstdio>
#include <algorithm>
#define maxn 1010
using namespace std;
int f[maxn][maxn], s[maxn], N, M, top, g[maxn][maxn];
void init()
{
int i, j; char s[10];
scanf("%d%d",&N,&M);
for(i=1;i<=N;i++)for(j=1;j<=M;j++)
{
scanf("%s",s);
if(*s=='F')f[i][j]=f[i][j-1]+1;
}
}
void work(int x)
{
int i, top;
s[top=0]=0;
for(i=1;i<=N;i++)
{
while(top and f[s[top]][x]>=f[i][x])top--;
s[++top]=i;
g[i][x]=i-s[top-1];
}
s[top=0]=N+1;
for(i=N;i;i--)
{
while(top and f[s[top]][x]>=f[i][x])top--;
s[++top]=i;
g[i][x]+=s[top-1]-1-i;
}
}
void calc()
{
int ans=0, i, j;
for(j=1;j<=M;j++)work(j);
for(i=1;i<=N;i++)for(j=1;j<=M;j++)ans=max(ans,g[i][j]*f[i][j]);
printf("%d",ans*3);
}
int main()
{
init();
calc();
return 0;
}