Submission #15045

#TimeUsernameProblemLanguageResultExecution timeMemory
15045hongjun7빨간 직사각형 (kriii3_QQ)C++98
20 / 20
363 ms45696 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...