# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92694 | 2019-01-04T10:28:37 Z | Kastanda | Strah (COCI18_strah) | C++11 | 118 ms | 28068 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 | 2 ms | 508 KB | Output is correct |
2 | Incorrect | 2 ms | 504 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2808 KB | Output is correct |
2 | Correct | 6 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2808 KB | Output is correct |
2 | Correct | 6 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 10744 KB | Output is correct |
2 | Correct | 76 ms | 18416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 68 ms | 18596 KB | Output is correct |
2 | Correct | 115 ms | 24072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 50 ms | 10492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 12920 KB | Output is correct |
2 | Correct | 92 ms | 21864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 118 ms | 24184 KB | Output is correct |
2 | Correct | 117 ms | 28068 KB | Output is correct |