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 <cstdio>
#include <stack>
using namespace std;
int height[3005];
char str[3005];
int n, m;
long long ret;
int main(){
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++){
scanf("%s",str + 1);
stack<int> hi, pos, area;
hi.push(0);
pos.push(0);
area.push(0);
for(int j=1; j<=m; j++){
if(str[j] == 'R') height[j]++;
else height[j] = 0;
while(!hi.empty() && hi.top() > height[j]){
hi.pop();
area.pop();
pos.pop();
}
area.push(area.top() + (j - pos.top()) * height[j]);
pos.push(j);
hi.push(height[j]);
ret += area.top();
}
}
printf("%lld",ret);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |