This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<algorithm>
#include<memory.h>
#include<stack>
#include<utility>
using namespace std;
const int max_n = 1010;
int n,m,h[max_n][max_n];
long long ans;
char a[max_n][max_n];
int main() {
ios_base::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) if(a[0][i]=='R') h[0][i] = 1;
for(int i=1;i<n;i++) {
for(int j=0;j<m;j++) {
if(a[i][j] == 'R') h[i][j] = h[i-1][j]+1;
}
}
for(int i=0;i<n;i++) {
stack<pair<int,int> > s;
s.push(make_pair(-1,-1));
for(int j=0;j<m;j++) {
pair<int,int> now = make_pair(j,h[i][j]);
while(1) {
pair<int,int> T = s.top();
if(T.second >= now.second) s.pop();
else break;
}
int width = j-s.top().first;
ans += 1LL * width * now.second;
s.push(now);
}
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |