# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48090 | 2018-05-10T04:38:54 Z | jeff | Fireworks (APIO16_fireworks) | C++14 | 343 ms | 94584 KB |
#include <bits/stdc++.h> using namespace std; long long N, M, l[300000], r[300000]; priority_queue<long long> pq[300000]; vector<long long> adj[300000]; void it(long long i) { if (i + 1 > N) { pq[i].push(l[i]); pq[i].push(l[i]); r[i] = -l[i]; return; } long long x = 0, z, j; pair<long long, long long> p = make_pair(0, 0); for (j = 0; j < adj[i].size(); ++j) { it(adj[i][j]); x = max(x, pq[adj[i][j]].top()); p = max(p, make_pair((long long) pq[adj[i][j]].size(), j)); } swap(r[i], r[adj[i][p.second]]); swap(pq[i], pq[adj[i][p.second]]); z = x + r[i]; for (j = 0; j < adj[i].size(); ++j) if (p.second != j) { z += x + r[adj[i][j]]; while (!pq[adj[i][j]].empty()) pq[i].push(pq[adj[i][j]].top()), pq[adj[i][j]].pop(); } r[i] = z - adj[i].size() * x; for (j = 0; j < adj[i].size() - 1; ++j) r[i] += pq[i].top(), pq[i].pop(); x = pq[i].top(); pq[i].pop(); z = pq[i].top(); pq[i].pop(); pq[i].push(x + l[i]); pq[i].push(z + l[i]); r[i] -= l[i]; } int main() { long long a, b, i; scanf("%lld %lld", &N, &M); for (i = 1; i < N + M; ++i) scanf("%lld %lld", &a, &b), adj[--a].push_back(i), l[i] = b; it(0); printf("%lld", pq[0].top() + r[0]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 16760 KB | Output is correct |
2 | Correct | 20 ms | 16760 KB | Output is correct |
3 | Correct | 16 ms | 16936 KB | Output is correct |
4 | Correct | 15 ms | 16992 KB | Output is correct |
5 | Correct | 15 ms | 17064 KB | Output is correct |
6 | Correct | 14 ms | 17064 KB | Output is correct |
7 | Correct | 15 ms | 17064 KB | Output is correct |
8 | Correct | 15 ms | 17064 KB | Output is correct |
9 | Correct | 15 ms | 17064 KB | Output is correct |
10 | Correct | 16 ms | 17064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 17064 KB | Output is correct |
2 | Correct | 15 ms | 17064 KB | Output is correct |
3 | Correct | 16 ms | 17064 KB | Output is correct |
4 | Correct | 15 ms | 17064 KB | Output is correct |
5 | Correct | 14 ms | 17064 KB | Output is correct |
6 | Correct | 16 ms | 17064 KB | Output is correct |
7 | Correct | 15 ms | 17064 KB | Output is correct |
8 | Correct | 15 ms | 17064 KB | Output is correct |
9 | Correct | 16 ms | 17064 KB | Output is correct |
10 | Correct | 15 ms | 17064 KB | Output is correct |
11 | Correct | 15 ms | 17064 KB | Output is correct |
12 | Correct | 15 ms | 17064 KB | Output is correct |
13 | Correct | 15 ms | 17076 KB | Output is correct |
14 | Correct | 15 ms | 17080 KB | Output is correct |
15 | Correct | 15 ms | 17084 KB | Output is correct |
16 | Correct | 15 ms | 17088 KB | Output is correct |
17 | Correct | 15 ms | 17220 KB | Output is correct |
18 | Correct | 15 ms | 17220 KB | Output is correct |
19 | Correct | 16 ms | 17220 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 16760 KB | Output is correct |
2 | Correct | 20 ms | 16760 KB | Output is correct |
3 | Correct | 16 ms | 16936 KB | Output is correct |
4 | Correct | 15 ms | 16992 KB | Output is correct |
5 | Correct | 15 ms | 17064 KB | Output is correct |
6 | Correct | 14 ms | 17064 KB | Output is correct |
7 | Correct | 15 ms | 17064 KB | Output is correct |
8 | Correct | 15 ms | 17064 KB | Output is correct |
9 | Correct | 15 ms | 17064 KB | Output is correct |
10 | Correct | 16 ms | 17064 KB | Output is correct |
11 | Correct | 16 ms | 17064 KB | Output is correct |
12 | Correct | 15 ms | 17064 KB | Output is correct |
13 | Correct | 16 ms | 17064 KB | Output is correct |
14 | Correct | 15 ms | 17064 KB | Output is correct |
15 | Correct | 14 ms | 17064 KB | Output is correct |
16 | Correct | 16 ms | 17064 KB | Output is correct |
17 | Correct | 15 ms | 17064 KB | Output is correct |
18 | Correct | 15 ms | 17064 KB | Output is correct |
19 | Correct | 16 ms | 17064 KB | Output is correct |
20 | Correct | 15 ms | 17064 KB | Output is correct |
21 | Correct | 15 ms | 17064 KB | Output is correct |
22 | Correct | 15 ms | 17064 KB | Output is correct |
23 | Correct | 15 ms | 17076 KB | Output is correct |
24 | Correct | 15 ms | 17080 KB | Output is correct |
25 | Correct | 15 ms | 17084 KB | Output is correct |
26 | Correct | 15 ms | 17088 KB | Output is correct |
27 | Correct | 15 ms | 17220 KB | Output is correct |
28 | Correct | 15 ms | 17220 KB | Output is correct |
29 | Correct | 16 ms | 17220 KB | Output is correct |
30 | Correct | 15 ms | 17220 KB | Output is correct |
31 | Correct | 16 ms | 17232 KB | Output is correct |
32 | Correct | 16 ms | 17248 KB | Output is correct |
33 | Correct | 17 ms | 17272 KB | Output is correct |
34 | Correct | 17 ms | 17444 KB | Output is correct |
35 | Correct | 18 ms | 17476 KB | Output is correct |
36 | Correct | 18 ms | 17656 KB | Output is correct |
37 | Correct | 19 ms | 17716 KB | Output is correct |
38 | Correct | 18 ms | 17780 KB | Output is correct |
39 | Correct | 18 ms | 17848 KB | Output is correct |
40 | Correct | 17 ms | 18688 KB | Output is correct |
41 | Correct | 18 ms | 18832 KB | Output is correct |
42 | Correct | 17 ms | 18832 KB | Output is correct |
43 | Correct | 18 ms | 18832 KB | Output is correct |
44 | Correct | 19 ms | 18832 KB | Output is correct |
45 | Correct | 25 ms | 18832 KB | Output is correct |
46 | Correct | 19 ms | 18832 KB | Output is correct |
47 | Correct | 19 ms | 18832 KB | Output is correct |
48 | Correct | 19 ms | 18832 KB | Output is correct |
49 | Correct | 19 ms | 18832 KB | Output is correct |
50 | Correct | 18 ms | 18832 KB | Output is correct |
51 | Correct | 18 ms | 18832 KB | Output is correct |
52 | Correct | 19 ms | 18832 KB | Output is correct |
53 | Correct | 20 ms | 18920 KB | Output is correct |
54 | Correct | 20 ms | 19000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 16760 KB | Output is correct |
2 | Correct | 20 ms | 16760 KB | Output is correct |
3 | Correct | 16 ms | 16936 KB | Output is correct |
4 | Correct | 15 ms | 16992 KB | Output is correct |
5 | Correct | 15 ms | 17064 KB | Output is correct |
6 | Correct | 14 ms | 17064 KB | Output is correct |
7 | Correct | 15 ms | 17064 KB | Output is correct |
8 | Correct | 15 ms | 17064 KB | Output is correct |
9 | Correct | 15 ms | 17064 KB | Output is correct |
10 | Correct | 16 ms | 17064 KB | Output is correct |
11 | Correct | 16 ms | 17064 KB | Output is correct |
12 | Correct | 15 ms | 17064 KB | Output is correct |
13 | Correct | 16 ms | 17064 KB | Output is correct |
14 | Correct | 15 ms | 17064 KB | Output is correct |
15 | Correct | 14 ms | 17064 KB | Output is correct |
16 | Correct | 16 ms | 17064 KB | Output is correct |
17 | Correct | 15 ms | 17064 KB | Output is correct |
18 | Correct | 15 ms | 17064 KB | Output is correct |
19 | Correct | 16 ms | 17064 KB | Output is correct |
20 | Correct | 15 ms | 17064 KB | Output is correct |
21 | Correct | 15 ms | 17064 KB | Output is correct |
22 | Correct | 15 ms | 17064 KB | Output is correct |
23 | Correct | 15 ms | 17076 KB | Output is correct |
24 | Correct | 15 ms | 17080 KB | Output is correct |
25 | Correct | 15 ms | 17084 KB | Output is correct |
26 | Correct | 15 ms | 17088 KB | Output is correct |
27 | Correct | 15 ms | 17220 KB | Output is correct |
28 | Correct | 15 ms | 17220 KB | Output is correct |
29 | Correct | 16 ms | 17220 KB | Output is correct |
30 | Correct | 15 ms | 17220 KB | Output is correct |
31 | Correct | 16 ms | 17232 KB | Output is correct |
32 | Correct | 16 ms | 17248 KB | Output is correct |
33 | Correct | 17 ms | 17272 KB | Output is correct |
34 | Correct | 17 ms | 17444 KB | Output is correct |
35 | Correct | 18 ms | 17476 KB | Output is correct |
36 | Correct | 18 ms | 17656 KB | Output is correct |
37 | Correct | 19 ms | 17716 KB | Output is correct |
38 | Correct | 18 ms | 17780 KB | Output is correct |
39 | Correct | 18 ms | 17848 KB | Output is correct |
40 | Correct | 17 ms | 18688 KB | Output is correct |
41 | Correct | 18 ms | 18832 KB | Output is correct |
42 | Correct | 17 ms | 18832 KB | Output is correct |
43 | Correct | 18 ms | 18832 KB | Output is correct |
44 | Correct | 19 ms | 18832 KB | Output is correct |
45 | Correct | 25 ms | 18832 KB | Output is correct |
46 | Correct | 19 ms | 18832 KB | Output is correct |
47 | Correct | 19 ms | 18832 KB | Output is correct |
48 | Correct | 19 ms | 18832 KB | Output is correct |
49 | Correct | 19 ms | 18832 KB | Output is correct |
50 | Correct | 18 ms | 18832 KB | Output is correct |
51 | Correct | 18 ms | 18832 KB | Output is correct |
52 | Correct | 19 ms | 18832 KB | Output is correct |
53 | Correct | 20 ms | 18920 KB | Output is correct |
54 | Correct | 20 ms | 19000 KB | Output is correct |
55 | Correct | 25 ms | 19556 KB | Output is correct |
56 | Correct | 75 ms | 22820 KB | Output is correct |
57 | Correct | 111 ms | 26204 KB | Output is correct |
58 | Correct | 137 ms | 29312 KB | Output is correct |
59 | Correct | 184 ms | 33008 KB | Output is correct |
60 | Correct | 247 ms | 35248 KB | Output is correct |
61 | Correct | 258 ms | 37224 KB | Output is correct |
62 | Correct | 287 ms | 38504 KB | Output is correct |
63 | Correct | 335 ms | 41184 KB | Output is correct |
64 | Correct | 343 ms | 42092 KB | Output is correct |
65 | Correct | 170 ms | 89712 KB | Output is correct |
66 | Correct | 167 ms | 94584 KB | Output is correct |
67 | Correct | 183 ms | 94584 KB | Output is correct |
68 | Correct | 230 ms | 94584 KB | Output is correct |
69 | Correct | 283 ms | 94584 KB | Output is correct |
70 | Correct | 280 ms | 94584 KB | Output is correct |
71 | Correct | 272 ms | 94584 KB | Output is correct |
72 | Correct | 257 ms | 94584 KB | Output is correct |
73 | Correct | 215 ms | 94584 KB | Output is correct |
74 | Correct | 213 ms | 94584 KB | Output is correct |
75 | Correct | 215 ms | 94584 KB | Output is correct |
76 | Correct | 209 ms | 94584 KB | Output is correct |
77 | Correct | 218 ms | 94584 KB | Output is correct |
78 | Correct | 217 ms | 94584 KB | Output is correct |
79 | Correct | 211 ms | 94584 KB | Output is correct |