# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42896 | 2018-03-06T08:02:16 Z | PowerOfNinjaGo | Fireworks (APIO16_fireworks) | C++14 | 252 ms | 131168 KB |
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii; typedef long long L; typedef vector< L > vL; typedef vector< vL > vvL; typedef vector< vi > vvi; typedef vector< vii > vvii; const int inf = 1e9; const L inf8 = 1e18; int p[300005], c[300005]; struct node { L a, b; priority_queue<L> *pq; node operator+(node r) { node res; res.a = a + r.a; res.b = b + r.b; if(pq->size()> r.pq->size()) { res.pq = pq; while(r.pq->size()> 0) { res.pq->push(r.pq->top()); r.pq->pop(); } } else { res.pq = r.pq; while(pq->size()> 0) { res.pq->push(pq->top()); pq->pop(); } } return res; } }; node f[300005]; int main() { int n, m; scanf("%d %d", &n, &m); for(int i = 2; i<= n+m; i++) scanf("%d %d", p+i, c+i); for(int i = 1; i<= n+m; i++) { f[i].a = f[i].b = 0; f[i].pq = new priority_queue<L>; } for(int i = n+1; i<= n+m; i++) { f[i].a = 1; f[i].b = -c[i]; f[i].pq->push(c[i]); f[i].pq->push(c[i]); f[p[i]] = f[p[i]]+f[i]; } for(int i = n; i> 1; i--) { while(f[i].a> 1) { f[i].b += f[i].pq->top(); f[i].pq->pop(); f[i].a--; } L k1 = f[i].pq->top(); f[i].pq->pop(); L k2 = f[i].pq->top(); f[i].pq->pop(); f[i].pq->push(k1+c[i]); f[i].pq->push(k2+c[i]); f[i].b -= c[i]; f[p[i]] = f[p[i]]+f[i]; } while(f[1].a> 0) { f[1].a--; f[1].b += f[1].pq->top(); f[1].pq->pop(); } cout << f[1].b << endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 488 KB | Output is correct |
5 | Correct | 2 ms | 564 KB | Output is correct |
6 | Correct | 2 ms | 600 KB | Output is correct |
7 | Correct | 2 ms | 604 KB | Output is correct |
8 | Correct | 2 ms | 628 KB | Output is correct |
9 | Correct | 2 ms | 628 KB | Output is correct |
10 | Correct | 2 ms | 628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 632 KB | Output is correct |
2 | Correct | 2 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 760 KB | Output is correct |
4 | Correct | 2 ms | 760 KB | Output is correct |
5 | Correct | 2 ms | 760 KB | Output is correct |
6 | Correct | 2 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 932 KB | Output is correct |
8 | Correct | 1 ms | 932 KB | Output is correct |
9 | Correct | 2 ms | 932 KB | Output is correct |
10 | Correct | 2 ms | 932 KB | Output is correct |
11 | Correct | 2 ms | 932 KB | Output is correct |
12 | Correct | 2 ms | 932 KB | Output is correct |
13 | Correct | 2 ms | 932 KB | Output is correct |
14 | Correct | 1 ms | 932 KB | Output is correct |
15 | Correct | 2 ms | 932 KB | Output is correct |
16 | Correct | 2 ms | 932 KB | Output is correct |
17 | Correct | 2 ms | 932 KB | Output is correct |
18 | Correct | 2 ms | 932 KB | Output is correct |
19 | Correct | 2 ms | 932 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 488 KB | Output is correct |
5 | Correct | 2 ms | 564 KB | Output is correct |
6 | Correct | 2 ms | 600 KB | Output is correct |
7 | Correct | 2 ms | 604 KB | Output is correct |
8 | Correct | 2 ms | 628 KB | Output is correct |
9 | Correct | 2 ms | 628 KB | Output is correct |
10 | Correct | 2 ms | 628 KB | Output is correct |
11 | Correct | 2 ms | 632 KB | Output is correct |
12 | Correct | 2 ms | 632 KB | Output is correct |
13 | Correct | 2 ms | 760 KB | Output is correct |
14 | Correct | 2 ms | 760 KB | Output is correct |
15 | Correct | 2 ms | 760 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 932 KB | Output is correct |
18 | Correct | 1 ms | 932 KB | Output is correct |
19 | Correct | 2 ms | 932 KB | Output is correct |
20 | Correct | 2 ms | 932 KB | Output is correct |
21 | Correct | 2 ms | 932 KB | Output is correct |
22 | Correct | 2 ms | 932 KB | Output is correct |
23 | Correct | 2 ms | 932 KB | Output is correct |
24 | Correct | 1 ms | 932 KB | Output is correct |
25 | Correct | 2 ms | 932 KB | Output is correct |
26 | Correct | 2 ms | 932 KB | Output is correct |
27 | Correct | 2 ms | 932 KB | Output is correct |
28 | Correct | 2 ms | 932 KB | Output is correct |
29 | Correct | 2 ms | 932 KB | Output is correct |
30 | Correct | 2 ms | 944 KB | Output is correct |
31 | Correct | 2 ms | 1088 KB | Output is correct |
32 | Correct | 3 ms | 1100 KB | Output is correct |
33 | Correct | 3 ms | 1268 KB | Output is correct |
34 | Correct | 3 ms | 1428 KB | Output is correct |
35 | Correct | 4 ms | 1532 KB | Output is correct |
36 | Correct | 4 ms | 1592 KB | Output is correct |
37 | Correct | 4 ms | 1716 KB | Output is correct |
38 | Correct | 4 ms | 1780 KB | Output is correct |
39 | Correct | 5 ms | 1980 KB | Output is correct |
40 | Correct | 3 ms | 1980 KB | Output is correct |
41 | Correct | 3 ms | 1980 KB | Output is correct |
42 | Correct | 3 ms | 1980 KB | Output is correct |
43 | Correct | 4 ms | 2204 KB | Output is correct |
44 | Correct | 4 ms | 2252 KB | Output is correct |
45 | Correct | 4 ms | 2324 KB | Output is correct |
46 | Correct | 5 ms | 2652 KB | Output is correct |
47 | Correct | 5 ms | 2716 KB | Output is correct |
48 | Correct | 4 ms | 2716 KB | Output is correct |
49 | Correct | 6 ms | 2836 KB | Output is correct |
50 | Correct | 4 ms | 2836 KB | Output is correct |
51 | Correct | 4 ms | 2836 KB | Output is correct |
52 | Correct | 4 ms | 2872 KB | Output is correct |
53 | Correct | 4 ms | 2936 KB | Output is correct |
54 | Correct | 4 ms | 3124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 488 KB | Output is correct |
5 | Correct | 2 ms | 564 KB | Output is correct |
6 | Correct | 2 ms | 600 KB | Output is correct |
7 | Correct | 2 ms | 604 KB | Output is correct |
8 | Correct | 2 ms | 628 KB | Output is correct |
9 | Correct | 2 ms | 628 KB | Output is correct |
10 | Correct | 2 ms | 628 KB | Output is correct |
11 | Correct | 2 ms | 632 KB | Output is correct |
12 | Correct | 2 ms | 632 KB | Output is correct |
13 | Correct | 2 ms | 760 KB | Output is correct |
14 | Correct | 2 ms | 760 KB | Output is correct |
15 | Correct | 2 ms | 760 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 932 KB | Output is correct |
18 | Correct | 1 ms | 932 KB | Output is correct |
19 | Correct | 2 ms | 932 KB | Output is correct |
20 | Correct | 2 ms | 932 KB | Output is correct |
21 | Correct | 2 ms | 932 KB | Output is correct |
22 | Correct | 2 ms | 932 KB | Output is correct |
23 | Correct | 2 ms | 932 KB | Output is correct |
24 | Correct | 1 ms | 932 KB | Output is correct |
25 | Correct | 2 ms | 932 KB | Output is correct |
26 | Correct | 2 ms | 932 KB | Output is correct |
27 | Correct | 2 ms | 932 KB | Output is correct |
28 | Correct | 2 ms | 932 KB | Output is correct |
29 | Correct | 2 ms | 932 KB | Output is correct |
30 | Correct | 2 ms | 944 KB | Output is correct |
31 | Correct | 2 ms | 1088 KB | Output is correct |
32 | Correct | 3 ms | 1100 KB | Output is correct |
33 | Correct | 3 ms | 1268 KB | Output is correct |
34 | Correct | 3 ms | 1428 KB | Output is correct |
35 | Correct | 4 ms | 1532 KB | Output is correct |
36 | Correct | 4 ms | 1592 KB | Output is correct |
37 | Correct | 4 ms | 1716 KB | Output is correct |
38 | Correct | 4 ms | 1780 KB | Output is correct |
39 | Correct | 5 ms | 1980 KB | Output is correct |
40 | Correct | 3 ms | 1980 KB | Output is correct |
41 | Correct | 3 ms | 1980 KB | Output is correct |
42 | Correct | 3 ms | 1980 KB | Output is correct |
43 | Correct | 4 ms | 2204 KB | Output is correct |
44 | Correct | 4 ms | 2252 KB | Output is correct |
45 | Correct | 4 ms | 2324 KB | Output is correct |
46 | Correct | 5 ms | 2652 KB | Output is correct |
47 | Correct | 5 ms | 2716 KB | Output is correct |
48 | Correct | 4 ms | 2716 KB | Output is correct |
49 | Correct | 6 ms | 2836 KB | Output is correct |
50 | Correct | 4 ms | 2836 KB | Output is correct |
51 | Correct | 4 ms | 2836 KB | Output is correct |
52 | Correct | 4 ms | 2872 KB | Output is correct |
53 | Correct | 4 ms | 2936 KB | Output is correct |
54 | Correct | 4 ms | 3124 KB | Output is correct |
55 | Correct | 9 ms | 4080 KB | Output is correct |
56 | Correct | 31 ms | 9008 KB | Output is correct |
57 | Correct | 59 ms | 14232 KB | Output is correct |
58 | Correct | 76 ms | 18636 KB | Output is correct |
59 | Correct | 103 ms | 24968 KB | Output is correct |
60 | Correct | 135 ms | 31588 KB | Output is correct |
61 | Correct | 146 ms | 37812 KB | Output is correct |
62 | Correct | 176 ms | 43852 KB | Output is correct |
63 | Correct | 204 ms | 52712 KB | Output is correct |
64 | Correct | 235 ms | 58584 KB | Output is correct |
65 | Correct | 105 ms | 58584 KB | Output is correct |
66 | Correct | 105 ms | 59808 KB | Output is correct |
67 | Correct | 113 ms | 64836 KB | Output is correct |
68 | Correct | 177 ms | 76264 KB | Output is correct |
69 | Correct | 213 ms | 81676 KB | Output is correct |
70 | Correct | 204 ms | 86424 KB | Output is correct |
71 | Correct | 230 ms | 106120 KB | Output is correct |
72 | Correct | 228 ms | 110484 KB | Output is correct |
73 | Correct | 252 ms | 110972 KB | Output is correct |
74 | Correct | 230 ms | 115788 KB | Output is correct |
75 | Correct | 235 ms | 117820 KB | Output is correct |
76 | Correct | 226 ms | 121892 KB | Output is correct |
77 | Correct | 224 ms | 124944 KB | Output is correct |
78 | Correct | 217 ms | 128388 KB | Output is correct |
79 | Correct | 207 ms | 131168 KB | Output is correct |