MnZn求助91分
  • 板块P4147 玉蟾宫
  • 楼主巴菲特脆脆鲨
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/7/5 19:38
  • 上次更新2023/11/4 18:35:18
查看原帖
MnZn求助91分
171851
巴菲特脆脆鲨楼主2021/7/5 19:38

单调栈做法,如果最后增添一个高度为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;
}


2021/7/5 19:38
加载中...