# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
65667 | 2018-08-08T11:12:45 Z | imeimi2000 | None (KOI18_watertank) | C++17 | 477 ms | 157428 KB |
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n, m, h; int hp[1001][1001]; int vp[1001][1001]; int dist[1001][1001]; vector<pii> hs[1001]; int main() { scanf("%d%d%d", &n, &m, &h); for (int i = 0; i <= n; ++i) { for (int j = 1; j <= m; ++j) { scanf("%d", hp[i] + j); if (hp[i][j] == -1) hp[i][j] = h; } } for (int i = 1; i <= n; ++i) { for (int j = 0; j <= m; ++j) { scanf("%d", vp[i] + j); if (vp[i][j] == -1) vp[i][j] = h; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { dist[i][j] = h; } } for (int i = 1; i <= n; ++i) { dist[i][1] = min(dist[i][1], vp[i][0]); dist[i][m] = min(dist[i][m], vp[i][m]); } for (int i = 1; i <= m; ++i) { dist[1][i] = min(dist[1][i], hp[0][i]); dist[n][i] = min(dist[n][i], hp[n][i]); } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { hs[dist[i][j]].emplace_back(i, j); } } for (int it = 0; it < h; ++it) { vector<pii> &st = hs[it]; while (!st.empty()) { int x, y; tie(x, y) = st.back(); st.pop_back(); if (dist[x][y] != it) continue; int d; d = max(dist[x][y], hp[x - 1][y]); if (d < dist[x - 1][y]) { hs[dist[x - 1][y] = d].emplace_back(x - 1, y); } d = max(dist[x][y], hp[x][y]); if (d < dist[x + 1][y]) { hs[dist[x + 1][y] = d].emplace_back(x + 1, y); } d = max(dist[x][y], vp[x][y - 1]); if (d < dist[x][y - 1]) { hs[dist[x][y - 1] = d].emplace_back(x, y - 1); } d = max(dist[x][y], vp[x][y]); if (d < dist[x][y + 1]) { hs[dist[x][y + 1] = d].emplace_back(x, y + 1); } } } int ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { ans += dist[i][j]; } } printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 3 ms | 664 KB | Output is correct |
5 | Correct | 2 ms | 664 KB | Output is correct |
6 | Correct | 3 ms | 772 KB | Output is correct |
7 | Correct | 3 ms | 772 KB | Output is correct |
8 | Correct | 2 ms | 772 KB | Output is correct |
9 | Correct | 4 ms | 780 KB | Output is correct |
10 | Correct | 3 ms | 780 KB | Output is correct |
11 | Correct | 2 ms | 780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 780 KB | Output is correct |
2 | Correct | 3 ms | 780 KB | Output is correct |
3 | Correct | 4 ms | 856 KB | Output is correct |
4 | Correct | 3 ms | 856 KB | Output is correct |
5 | Correct | 4 ms | 856 KB | Output is correct |
6 | Correct | 3 ms | 856 KB | Output is correct |
7 | Correct | 3 ms | 856 KB | Output is correct |
8 | Correct | 3 ms | 856 KB | Output is correct |
9 | Correct | 2 ms | 920 KB | Output is correct |
10 | Correct | 3 ms | 928 KB | Output is correct |
11 | Correct | 4 ms | 988 KB | Output is correct |
12 | Correct | 2 ms | 988 KB | Output is correct |
13 | Correct | 4 ms | 988 KB | Output is correct |
14 | Correct | 3 ms | 1004 KB | Output is correct |
15 | Correct | 3 ms | 1004 KB | Output is correct |
16 | Correct | 3 ms | 1004 KB | Output is correct |
17 | Correct | 3 ms | 1004 KB | Output is correct |
18 | Correct | 2 ms | 1004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 233 ms | 26880 KB | Output is correct |
2 | Correct | 3 ms | 26880 KB | Output is correct |
3 | Correct | 178 ms | 30968 KB | Output is correct |
4 | Correct | 191 ms | 35868 KB | Output is correct |
5 | Correct | 2 ms | 35868 KB | Output is correct |
6 | Correct | 262 ms | 41684 KB | Output is correct |
7 | Correct | 211 ms | 45900 KB | Output is correct |
8 | Correct | 214 ms | 58032 KB | Output is correct |
9 | Correct | 193 ms | 58032 KB | Output is correct |
10 | Correct | 2 ms | 58032 KB | Output is correct |
11 | Correct | 345 ms | 61744 KB | Output is correct |
12 | Correct | 2 ms | 61744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 61744 KB | Output is correct |
2 | Correct | 2 ms | 61744 KB | Output is correct |
3 | Correct | 2 ms | 61744 KB | Output is correct |
4 | Correct | 3 ms | 61744 KB | Output is correct |
5 | Correct | 2 ms | 61744 KB | Output is correct |
6 | Correct | 2 ms | 61744 KB | Output is correct |
7 | Correct | 3 ms | 61744 KB | Output is correct |
8 | Correct | 4 ms | 61744 KB | Output is correct |
9 | Correct | 2 ms | 61744 KB | Output is correct |
10 | Correct | 4 ms | 61744 KB | Output is correct |
11 | Correct | 4 ms | 61744 KB | Output is correct |
12 | Correct | 3 ms | 61744 KB | Output is correct |
13 | Correct | 3 ms | 61744 KB | Output is correct |
14 | Correct | 2 ms | 61744 KB | Output is correct |
15 | Correct | 4 ms | 61744 KB | Output is correct |
16 | Correct | 4 ms | 61744 KB | Output is correct |
17 | Correct | 4 ms | 61744 KB | Output is correct |
18 | Correct | 4 ms | 61744 KB | Output is correct |
19 | Correct | 3 ms | 61744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 61744 KB | Output is correct |
2 | Correct | 3 ms | 61744 KB | Output is correct |
3 | Correct | 3 ms | 61744 KB | Output is correct |
4 | Correct | 2 ms | 61744 KB | Output is correct |
5 | Correct | 4 ms | 61744 KB | Output is correct |
6 | Correct | 239 ms | 65908 KB | Output is correct |
7 | Correct | 4 ms | 65908 KB | Output is correct |
8 | Correct | 3 ms | 65908 KB | Output is correct |
9 | Correct | 202 ms | 70900 KB | Output is correct |
10 | Correct | 5 ms | 70900 KB | Output is correct |
11 | Correct | 3 ms | 70900 KB | Output is correct |
12 | Correct | 233 ms | 76868 KB | Output is correct |
13 | Correct | 212 ms | 80884 KB | Output is correct |
14 | Correct | 3 ms | 80884 KB | Output is correct |
15 | Correct | 242 ms | 86000 KB | Output is correct |
16 | Correct | 3 ms | 86000 KB | Output is correct |
17 | Correct | 4 ms | 86000 KB | Output is correct |
18 | Correct | 3 ms | 86000 KB | Output is correct |
19 | Correct | 224 ms | 91108 KB | Output is correct |
20 | Correct | 5 ms | 91108 KB | Output is correct |
21 | Correct | 477 ms | 108296 KB | Output is correct |
22 | Correct | 4 ms | 108296 KB | Output is correct |
23 | Correct | 2 ms | 108296 KB | Output is correct |
24 | Correct | 3 ms | 108296 KB | Output is correct |
25 | Correct | 3 ms | 108296 KB | Output is correct |
26 | Correct | 4 ms | 108296 KB | Output is correct |
27 | Correct | 3 ms | 108296 KB | Output is correct |
28 | Correct | 279 ms | 108296 KB | Output is correct |
29 | Correct | 247 ms | 111404 KB | Output is correct |
30 | Correct | 195 ms | 115652 KB | Output is correct |
31 | Correct | 263 ms | 127684 KB | Output is correct |
32 | Correct | 213 ms | 127684 KB | Output is correct |
33 | Correct | 2 ms | 127684 KB | Output is correct |
34 | Correct | 177 ms | 129652 KB | Output is correct |
35 | Correct | 3 ms | 129652 KB | Output is correct |
36 | Correct | 2 ms | 129652 KB | Output is correct |
37 | Correct | 3 ms | 129652 KB | Output is correct |
38 | Correct | 235 ms | 137212 KB | Output is correct |
39 | Correct | 308 ms | 151072 KB | Output is correct |
40 | Correct | 3 ms | 151072 KB | Output is correct |
41 | Correct | 3 ms | 151072 KB | Output is correct |
42 | Correct | 4 ms | 151072 KB | Output is correct |
43 | Correct | 4 ms | 151072 KB | Output is correct |
44 | Correct | 198 ms | 151072 KB | Output is correct |
45 | Correct | 312 ms | 157428 KB | Output is correct |
46 | Correct | 3 ms | 157428 KB | Output is correct |