AcWing 152. 城市游戏
原题链接
中等
作者:
hxzz
,
2020-07-26 15:49:26
,
所有人可见
,
阅读 528
C++ 代码
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1010;
int h[N][N];
char g[N][N];
int s[N], w[N];
int n, m;
int work(int a[]) {
int p = 0;
a[m+1] = 0;
int ans = 0;
for(int i = 1; i <= m+1; ++ i) {
if(a[i] > s[p]) s[++p] = a[i], w[p] = 1;
else {
int width = 0;
while(s[p] > a[i]){
width += w[p];
ans = max(ans, width*s[p]);
p--;
}
s[++p] = a[i], w[p] = width + 1;
}
}
return ans;
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= m; ++ j)
{
char c;
cin >> c;
g[i][j] = c;
if(c == 'F') h[i][j] = h[i-1][j] + 1;
else h[i][j] = 0;
}
int ans = 0;
for(int i = 1; i <= n; ++ i) ans = max(ans, work(h[i]));
cout << ans * 3 << endl;
return 0;
}