分析:这题一开始以为原题。。51nod有一道求最大子矩阵和的方法,但是n^3,这题虽然要求弱了点,但是时间复杂度要求比较高,所以一开始想法是枚举矩阵的顶,然后二分出向左向右最长扩展距离,然后往下扫,但是这样log^2感觉会超。。后来发现单调栈可以直接做。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,m;
const int N=1e3+5;
typedef long long ll;
char s[N];
int a[N][N];
int l[N],r[N],h[N],st[N],top=0,ans;
int main()
{
scanf("%d%d",&n,&m);
fo(i,1,n)
{
fo(j,1,m)
{
char ch;
ch=getchar();
while(ch!='F'&&ch!='R')ch=getchar();
if (ch=='F')a[i][j]=1;
}
}
fo(i,1,n)
{
fo(j,1,m)
if (a[i][j])h[j]++;
else h[j]=0;
top=0;
st[top]=0;
fo(j,1,m)
{
while (h[st[top]]>=h[j]&&top)top--;
l[j]=st[top]+1;
st[++top]=j;
}
top=0;
st[top]=m+1;
fd(j,m,1)
{
while (h[st[top]]>=h[j]&&top)top--;
r[j]=st[top]-1;
st[++top]=j;
}
fo(j,1,m)
ans=max(ans,h[j]*(r[j]-l[j]+1));
}
printf("%d\n",ans*3);
}