单调栈
2025-08-14 17:08:18
发布于:浙江
1阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
char mp[1001][1001];
int n,m,a[1001],l[1001],r[1001];
long long ans;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
stack<int> s;
for(int j=1;j<=m;j++){
cin>>mp[i][j];
if(mp[i][j]=='R')a[j]=0;
else a[j]++;
}
for(int j=1;j<=m;j++)r[j]=m;
for(int j=1;j<=m;j++){
while(s.size()&&a[s.top()]>a[j]){
r[s.top()]=j-1;
s.pop();
}s.push(j);
}
while(s.size())s.pop();
for(int j=1;j<=m;j++)l[j]=1;
for(int j=m;j>=1;j--){
while(s.size()&&a[s.top()]>a[j]){
l[s.top()]=j+1;
s.pop();
}s.push(j);
}
for(int j=1;j<=m;j++){
long long cnt=(r[j]-l[j]+1)*a[j];
ans=max(ans,cnt);
}
}
cout<<ans*3;
return 0;
}
这里空空如也
有帮助,赞一个