이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
int n, m;
int nu[3005][3005];
char S[3005][3005];
long long d[3005];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%s", S[i] + 1);
for (int i = 1; i <= n; i++) {
for (int j = m; j >= 1; j--) {
nu[i][j] = S[i][j] == 'B' ? 0 : nu[i][j+1] + 1;
}
}
long long res = 0;
for (int i = 1; i <= m; i++) {
stack < pair <int, int> > s;
for (int j = 1; j <= n; j++) {
while (s.size() > 0 && s.top().first >= nu[j][i]) s.pop();
long long v = 0;
if (s.size() > 0) {
v = d[s.top().second];
d[j] = v + (long long)(j - s.top().second)*(nu[j][i]);
}
else
d[j] = (long long)(nu[j][i]) * (j);
s.push(make_pair(nu[j][i], j));
res += d[j];
}
}
printf("%lld", res);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |