이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stack>
#include<memory.h>
#define pi pair<int,int>
#define mp make_pair
using namespace std;
const int max_n = 3030;
int n,m,h[max_n],l[max_n],r[max_n];
long long ans;
char a[max_n];
int main() {
ios_base::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<n;i++) {
cin>>a;
for(int j=0;j<m;j++) {
if(a[j]=='R') h[j]++;
else h[j] = 0;
}
stack<pi> s;
s.push(mp(-1,-1));
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
for(int j=0;j<m;j++) {
while(1) {
pi T = s.top();
if(T.second >= h[j]) {
s.pop();
r[T.first] = j;
}
else break;
}
l[j] = s.top().first;
s.push(mp(j,h[j]));
}
while(!s.empty()) {
r[s.top().first] = m;
s.pop();
}
for(int j=0;j<m;j++) ans += 1LL * (r[j]-l[j]-1) * h[j];
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |