# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92698 | 2019-01-04T10:30:32 Z | Kastanda | Strah (COCI18_strah) | C++11 | 113 ms | 24156 KB |
#include<bits/stdc++.h> using namespace std; const int N = 2009; int n, m, dn[N][N], P[N]; long long tot, sum, dp[N]; char A[N][N]; vector < int > Q[N]; int Find(int v) { return ((P[v] > 0) ? (P[v] = Find(P[v])) : v); } inline void Merge(int v, int u) { v = Find(v); u = Find(u); if (v == u) return ; sum -= dp[-P[v]]; sum -= dp[-P[u]]; P[v] += P[u]; P[u] = v; sum += dp[-P[v]]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", &A[i][1]); for (int i = n; i; i--) for (int j = 1; j <= m; j++) { dn[i][j] = dn[i + 1][j]; if (A[i][j] == '#') dn[i][j] = i; else if (i == n) dn[i][j] = i + 1; } for (int i = 1; i < N; i++) for (int j = 1; j <= i; j++) dp[i] += (i - j + 1) * j; for (int i = 1; i <= n; i++) { sum = 0; memset(P, 0, sizeof(P)); for (int j = 1; j <= m; j++) Q[dn[i][j] - 1].push_back(j); for (int j = n; j >= i; j--) { for (int &id : Q[j]) { P[id] = -1; sum += dp[1]; if (P[id - 1]) Merge(id, id - 1); if (P[id + 1]) Merge(id, id + 1); } tot += 1ll * sum * (j - i + 1); } for (int j = 0; j <= n; j++) Q[j].clear(); } return !printf("%lld", tot); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 4 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 2596 KB | Output is correct |
2 | Correct | 8 ms | 2552 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 2680 KB | Output is correct |
2 | Correct | 8 ms | 2556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2552 KB | Output is correct |
2 | Correct | 7 ms | 2552 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 9720 KB | Output is correct |
2 | Correct | 78 ms | 16068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 16120 KB | Output is correct |
2 | Correct | 111 ms | 20472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 9080 KB | Output is correct |
2 | Correct | 88 ms | 19676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 12536 KB | Output is correct |
2 | Correct | 91 ms | 19028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 113 ms | 20088 KB | Output is correct |
2 | Correct | 111 ms | 24156 KB | Output is correct |