# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39868 | 2018-01-22T14:41:57 Z | cheater2k | Fireworks (APIO16_fireworks) | C++14 | 270 ms | 52464 KB |
#include <bits/stdc++.h> using namespace std; const int N = 300005; struct slope { priority_queue <long long> pq; long long starting_value; long long starting_slope; } S[N]; int n, m, p[N], a[N]; long long ans; void debug(slope &s) { priority_queue <long long> tmp = s.pq; vector<long long> ret; while(tmp.size()) { ret.push_back(tmp.top()); tmp.pop(); } reverse(ret.begin(), ret.end()); cerr << "DEBUG\n"; cerr << "starting value = " << s.starting_value << " starting_slope = " << s.starting_slope << endl; cerr << "[ "; for (auto c : ret) cerr << c << ' '; cerr << " ]\n"; } int main() { scanf("%d %d", &n, &m); for (int i = 2; i <= n + m; ++i) { scanf("%d %d", &p[i], &a[i]); if (i >= n + 1) { // leaf S[i].pq.push(a[i]); S[i].pq.push(a[i]); // -x + a and x - a S[i].starting_slope = -1; S[i].starting_value = a[i]; // -0 + a } } for (int i = n + m; i >= 2; --i) { if (i <= n) { // not leaf // fix slopes of S[i] long long last_slope = S[i].starting_slope + S[i].pq.size(); while(last_slope > 1) { S[i].pq.pop(); --last_slope; } //cerr << i << ' '; debug(S[i]); long long x1 = S[i].pq.top(); S[i].pq.pop(); // x-coordinate at slope 1 long long x0 = S[i].pq.top(); S[i].pq.pop(); // x-coordinate at slope 0 S[i].starting_value += a[i]; S[i].pq.push(x0 + a[i]); S[i].pq.push(x1 + a[i]); //cerr << i << ' '; debug(S[i]); } // update to p[i] int par = p[i]; if (S[par].pq.size() < S[i].pq.size()) { swap(S[par], S[i]); } S[par].starting_value += S[i].starting_value; S[par].starting_slope += S[i].starting_slope; while(!S[i].pq.empty()) { long long x = S[i].pq.top(); S[i].pq.pop(); S[par].pq.push(x); } } // root: 1 long long starting_value = S[1].starting_value; long long starting_slope = S[1].starting_slope; vector<long long> pts; while(!S[1].pq.empty()) { pts.push_back(S[1].pq.top()); S[1].pq.pop(); } pts.push_back(0); reverse(pts.begin(), pts.end()); ans = starting_value; for (int i = 1; i < pts.size(); ++i) { starting_value += starting_slope * (pts[i] - pts[i-1]); ++starting_slope; ans = min(ans, starting_value); } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 18428 KB | Output is correct |
2 | Correct | 3 ms | 18428 KB | Output is correct |
3 | Correct | 0 ms | 18428 KB | Output is correct |
4 | Correct | 0 ms | 18428 KB | Output is correct |
5 | Correct | 0 ms | 18428 KB | Output is correct |
6 | Correct | 3 ms | 18428 KB | Output is correct |
7 | Correct | 2 ms | 18428 KB | Output is correct |
8 | Correct | 0 ms | 18428 KB | Output is correct |
9 | Correct | 6 ms | 18428 KB | Output is correct |
10 | Correct | 2 ms | 18428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 18428 KB | Output is correct |
2 | Correct | 0 ms | 18428 KB | Output is correct |
3 | Correct | 3 ms | 18428 KB | Output is correct |
4 | Correct | 0 ms | 18428 KB | Output is correct |
5 | Correct | 4 ms | 18428 KB | Output is correct |
6 | Correct | 2 ms | 18428 KB | Output is correct |
7 | Correct | 3 ms | 18428 KB | Output is correct |
8 | Correct | 2 ms | 18428 KB | Output is correct |
9 | Correct | 0 ms | 18428 KB | Output is correct |
10 | Correct | 2 ms | 18428 KB | Output is correct |
11 | Correct | 0 ms | 18428 KB | Output is correct |
12 | Correct | 2 ms | 18428 KB | Output is correct |
13 | Correct | 0 ms | 18428 KB | Output is correct |
14 | Correct | 3 ms | 18428 KB | Output is correct |
15 | Correct | 3 ms | 18428 KB | Output is correct |
16 | Correct | 2 ms | 18428 KB | Output is correct |
17 | Correct | 5 ms | 18428 KB | Output is correct |
18 | Correct | 9 ms | 18428 KB | Output is correct |
19 | Correct | 6 ms | 18428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 18428 KB | Output is correct |
2 | Correct | 3 ms | 18428 KB | Output is correct |
3 | Correct | 0 ms | 18428 KB | Output is correct |
4 | Correct | 0 ms | 18428 KB | Output is correct |
5 | Correct | 0 ms | 18428 KB | Output is correct |
6 | Correct | 3 ms | 18428 KB | Output is correct |
7 | Correct | 2 ms | 18428 KB | Output is correct |
8 | Correct | 0 ms | 18428 KB | Output is correct |
9 | Correct | 6 ms | 18428 KB | Output is correct |
10 | Correct | 2 ms | 18428 KB | Output is correct |
11 | Correct | 2 ms | 18428 KB | Output is correct |
12 | Correct | 0 ms | 18428 KB | Output is correct |
13 | Correct | 3 ms | 18428 KB | Output is correct |
14 | Correct | 0 ms | 18428 KB | Output is correct |
15 | Correct | 4 ms | 18428 KB | Output is correct |
16 | Correct | 2 ms | 18428 KB | Output is correct |
17 | Correct | 3 ms | 18428 KB | Output is correct |
18 | Correct | 2 ms | 18428 KB | Output is correct |
19 | Correct | 0 ms | 18428 KB | Output is correct |
20 | Correct | 2 ms | 18428 KB | Output is correct |
21 | Correct | 0 ms | 18428 KB | Output is correct |
22 | Correct | 2 ms | 18428 KB | Output is correct |
23 | Correct | 0 ms | 18428 KB | Output is correct |
24 | Correct | 3 ms | 18428 KB | Output is correct |
25 | Correct | 3 ms | 18428 KB | Output is correct |
26 | Correct | 2 ms | 18428 KB | Output is correct |
27 | Correct | 5 ms | 18428 KB | Output is correct |
28 | Correct | 9 ms | 18428 KB | Output is correct |
29 | Correct | 6 ms | 18428 KB | Output is correct |
30 | Correct | 3 ms | 18428 KB | Output is correct |
31 | Correct | 2 ms | 18428 KB | Output is correct |
32 | Correct | 2 ms | 18560 KB | Output is correct |
33 | Correct | 3 ms | 18560 KB | Output is correct |
34 | Correct | 4 ms | 18560 KB | Output is correct |
35 | Correct | 4 ms | 18560 KB | Output is correct |
36 | Correct | 3 ms | 18560 KB | Output is correct |
37 | Correct | 6 ms | 18560 KB | Output is correct |
38 | Correct | 8 ms | 18700 KB | Output is correct |
39 | Correct | 0 ms | 18700 KB | Output is correct |
40 | Correct | 3 ms | 18428 KB | Output is correct |
41 | Correct | 7 ms | 18428 KB | Output is correct |
42 | Correct | 3 ms | 18428 KB | Output is correct |
43 | Correct | 11 ms | 18560 KB | Output is correct |
44 | Correct | 5 ms | 18720 KB | Output is correct |
45 | Correct | 7 ms | 18720 KB | Output is correct |
46 | Correct | 9 ms | 18996 KB | Output is correct |
47 | Correct | 9 ms | 18984 KB | Output is correct |
48 | Correct | 9 ms | 18836 KB | Output is correct |
49 | Correct | 9 ms | 18868 KB | Output is correct |
50 | Correct | 8 ms | 18860 KB | Output is correct |
51 | Correct | 8 ms | 18860 KB | Output is correct |
52 | Correct | 3 ms | 18848 KB | Output is correct |
53 | Correct | 4 ms | 18852 KB | Output is correct |
54 | Correct | 6 ms | 18924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 18428 KB | Output is correct |
2 | Correct | 3 ms | 18428 KB | Output is correct |
3 | Correct | 0 ms | 18428 KB | Output is correct |
4 | Correct | 0 ms | 18428 KB | Output is correct |
5 | Correct | 0 ms | 18428 KB | Output is correct |
6 | Correct | 3 ms | 18428 KB | Output is correct |
7 | Correct | 2 ms | 18428 KB | Output is correct |
8 | Correct | 0 ms | 18428 KB | Output is correct |
9 | Correct | 6 ms | 18428 KB | Output is correct |
10 | Correct | 2 ms | 18428 KB | Output is correct |
11 | Correct | 2 ms | 18428 KB | Output is correct |
12 | Correct | 0 ms | 18428 KB | Output is correct |
13 | Correct | 3 ms | 18428 KB | Output is correct |
14 | Correct | 0 ms | 18428 KB | Output is correct |
15 | Correct | 4 ms | 18428 KB | Output is correct |
16 | Correct | 2 ms | 18428 KB | Output is correct |
17 | Correct | 3 ms | 18428 KB | Output is correct |
18 | Correct | 2 ms | 18428 KB | Output is correct |
19 | Correct | 0 ms | 18428 KB | Output is correct |
20 | Correct | 2 ms | 18428 KB | Output is correct |
21 | Correct | 0 ms | 18428 KB | Output is correct |
22 | Correct | 2 ms | 18428 KB | Output is correct |
23 | Correct | 0 ms | 18428 KB | Output is correct |
24 | Correct | 3 ms | 18428 KB | Output is correct |
25 | Correct | 3 ms | 18428 KB | Output is correct |
26 | Correct | 2 ms | 18428 KB | Output is correct |
27 | Correct | 5 ms | 18428 KB | Output is correct |
28 | Correct | 9 ms | 18428 KB | Output is correct |
29 | Correct | 6 ms | 18428 KB | Output is correct |
30 | Correct | 3 ms | 18428 KB | Output is correct |
31 | Correct | 2 ms | 18428 KB | Output is correct |
32 | Correct | 2 ms | 18560 KB | Output is correct |
33 | Correct | 3 ms | 18560 KB | Output is correct |
34 | Correct | 4 ms | 18560 KB | Output is correct |
35 | Correct | 4 ms | 18560 KB | Output is correct |
36 | Correct | 3 ms | 18560 KB | Output is correct |
37 | Correct | 6 ms | 18560 KB | Output is correct |
38 | Correct | 8 ms | 18700 KB | Output is correct |
39 | Correct | 0 ms | 18700 KB | Output is correct |
40 | Correct | 3 ms | 18428 KB | Output is correct |
41 | Correct | 7 ms | 18428 KB | Output is correct |
42 | Correct | 3 ms | 18428 KB | Output is correct |
43 | Correct | 11 ms | 18560 KB | Output is correct |
44 | Correct | 5 ms | 18720 KB | Output is correct |
45 | Correct | 7 ms | 18720 KB | Output is correct |
46 | Correct | 9 ms | 18996 KB | Output is correct |
47 | Correct | 9 ms | 18984 KB | Output is correct |
48 | Correct | 9 ms | 18836 KB | Output is correct |
49 | Correct | 9 ms | 18868 KB | Output is correct |
50 | Correct | 8 ms | 18860 KB | Output is correct |
51 | Correct | 8 ms | 18860 KB | Output is correct |
52 | Correct | 3 ms | 18848 KB | Output is correct |
53 | Correct | 4 ms | 18852 KB | Output is correct |
54 | Correct | 6 ms | 18924 KB | Output is correct |
55 | Correct | 13 ms | 18960 KB | Output is correct |
56 | Correct | 32 ms | 20892 KB | Output is correct |
57 | Correct | 69 ms | 22056 KB | Output is correct |
58 | Correct | 84 ms | 23624 KB | Output is correct |
59 | Correct | 104 ms | 24848 KB | Output is correct |
60 | Correct | 145 ms | 26116 KB | Output is correct |
61 | Correct | 145 ms | 28372 KB | Output is correct |
62 | Correct | 174 ms | 29228 KB | Output is correct |
63 | Correct | 204 ms | 30856 KB | Output is correct |
64 | Correct | 212 ms | 30920 KB | Output is correct |
65 | Correct | 92 ms | 18428 KB | Output is correct |
66 | Correct | 84 ms | 18428 KB | Output is correct |
67 | Correct | 89 ms | 18560 KB | Output is correct |
68 | Correct | 170 ms | 29344 KB | Output is correct |
69 | Correct | 205 ms | 30504 KB | Output is correct |
70 | Correct | 222 ms | 30496 KB | Output is correct |
71 | Correct | 263 ms | 50476 KB | Output is correct |
72 | Correct | 270 ms | 50312 KB | Output is correct |
73 | Correct | 226 ms | 46496 KB | Output is correct |
74 | Correct | 267 ms | 47180 KB | Output is correct |
75 | Correct | 232 ms | 47000 KB | Output is correct |
76 | Correct | 249 ms | 47076 KB | Output is correct |
77 | Correct | 260 ms | 46892 KB | Output is correct |
78 | Correct | 233 ms | 45848 KB | Output is correct |
79 | Correct | 242 ms | 52464 KB | Output is correct |