思路:单调栈
这道题和上面的哪个AcWing 1413的题几乎是一样的,只不过这里给出了你地图,你需要自己处理地图,然后给每一个地图的点上赋值1,不多说了,如果需要,看以往的题解AcWing 1413.矩形牛棚-CSDN博客
这里就只说h数组的处理是怎么回事。
我仿照了上面的题目要求,每一块地看作是高度1,宽度1的方块点,所以才这样赋值。
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include <iomanip>
#include<sstream>
#include<numeric>
#include<map>
#include<limits.h>
#include<unordered_map>
#include<set>
#define int long long
#define MAX 2020
#define inf 0x3f3f3f3f
#define _for(i,a,b) for(int i=a;i<(b);i++)
using namespace std;
typedef pair<int, int> PII;
int n, m;
int counts;
int dx[] = { 0,1,0,-1};
int dy[] = { 1,0,-1,0 };
char maps[MAX][MAX];
int g[MAX][MAX];
int stk[MAX];
int top;
int h[MAX][MAX];
int l[MAX];
int r[MAX];
int work(int h[]) {
top = 0;
h[0] = -1;
h[m + 1] = -1;
stk[++top] = 0;
_for(i, 1, m + 1) {
while (h[stk[top]] >= h[i])top--;
l[i] = stk[top];
stk[++top] = i;
}
top = 0;
stk[++top] = m + 1;
for (int i = m; i; i--) {
while (h[stk[top]] >= h[i])top--;
r[i] = stk[top];
stk[++top] = i;
}
_for(i, 1, m + 1)
counts = max(counts, h[i] * (r[i] - l[i] - 1));
return counts;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> m;
_for(i, 1, n + 1) {
_for(j, 1, m + 1)
{
cin >> maps[i][j];
if (maps[i][j] == 'R')
g[i][j] = 1;
}
}
_for(i, 1, n + 1) {
_for(j, 1, m + 1) {
if (!g[i][j])
h[i][j] = 1;
}
}
_for(i, 1, n + 1) {
_for(j, 1, m + 1) {
if (!g[i][j]) {
h[i][j] += h[i - 1][j];
}
}
}
int res = 0;
_for(i, 1, n + 1) {
res = max(res, work(h[i]));
}
cout << res * 3 << endl;
return 0;
}