单调栈做法,如果最后增添一个高度为0的矩形,a[m + 1] = 0, 即 j <= m + 1
就AC了。
但是不那么做最后写一个while
去清空栈就WA一个点了。
求助。
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<functional>
#define ll long long
using namespace std;
#ifndef DONLINE_JUDGE
char xch, xB[1 << 15], *xS = xB, *xTT = xB;
#define getc() (xS == xTT && (xTT = (xS = xB) + fread(xB, 1, 1 << 15, stdin), xS == xTT) ? 0 : *xS++)
#endif
#ifndef DBUFFETT
#define getc() getchar()
#endif
int rd(){
int res = 0, fl = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') fl = -1;
c = getchar();
}
while(isdigit(c)){
res = (res << 3) + (res << 1) + c - '0';
c = getchar();
}
return res * fl;
}
int rdchar(){
char c = getchar();
while(!isalpha(c)){
c = getchar();
}
if(c == 'F') return 1;
else if(c == 'R') return 0;
}
int n, m, fld[1010][1010], ans;
int stk[1010], top, height[1010], w[1010];
int main(){
// freopen("P4147_7.in", "r", stdin);
n = rd(); m = rd();
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
fld[i][j] = rdchar();
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
if(fld[i][j]){
height[j] ++;
}
else height[j] = 0;
}
top = 0;
for(int j = 1; j <= m; ++j){
int width = 0;
while(top > 0 && stk[top] >= height[j]){
width += w[top];
ans = max(ans, width * stk[top--]);
}
stk[++top] = height[j];
w[top] = width + 1;
}
while(top > 0){
ans = max(ans, w[top] * stk[top]);
top--;
}
}
printf("%d\n", ans * 3);
return 0;
}