이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
char p[3002][3002];
int c[3002][3002], s[3002][2], d[3002];
long long ans;
int main(){
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)scanf("%s", p[i]+1);
for (int i = 1; i <= n; i++){
for (int j = 1, now = 0; j <= m; j++){
if (p[i][j] == 'R')c[i][j] = ++now;
else now = 0;
}
}
for (int i = 1; i <= m; i++){
for (int j = 1, top = 0; j <= n + 1; j++){
while (top && s[top - 1][1] >= c[j][i])--top;
if (top)d[j] = d[s[top - 1][0]] + (j - s[top - 1][0]) * c[j][i];
else d[j] = c[j][i] * j;
s[top][0] = j, s[top++][1] = c[j][i];
ans += d[j];
}
}
printf("%lld", ans);
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |