# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154100 | 2019-09-18T11:12:11 Z | mhy908 | Fireworks (APIO16_fireworks) | C++14 | 358 ms | 82168 KB |
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define mp make_pair #define llinf 8987654321987654321 #define inf 1987654321 using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; int n, m; vector<int> link[300010]; LL cost[300010]; struct dpfunc { LL sty, sta; priority_queue<LL> pq; void mergefunc(dpfunc &pl) { sty+=pl.sty; sta+=pl.sta; while(!pl.pq.empty()){ pq.push(pl.pq.top()); pl.pq.pop(); } } void makereal(LL c) { sty+=c; LL zeronum, onenum; while(1){ if(pq.size()==-sta-1)break; if(pq.size()==-sta)zeronum=pq.top(); if(pq.size()==-sta+1)onenum=pq.top(); pq.pop(); } zeronum+=c; onenum+=c; pq.push(zeronum); pq.push(onenum); } void init(LL st) { pq.push(st); pq.push(st); sty=st; sta=-1; } void del() { while(!pq.empty())pq.pop(); } }func[300010]; void get_dp(int num) { if(num>n){ func[num].init(cost[num]); return; } int maxsize=0, maxnum; for(int i=0; i<link[num].size(); i++){ get_dp(link[num][i]); int temp=func[link[num][i]].pq.size(); if(temp>maxsize){ maxsize=temp; maxnum=i; } } swap(func[link[num][0]], func[link[num][maxnum]]); swap(func[num], func[link[num][0]]); for(int i=1; i<link[num].size(); i++){ func[num].mergefunc(func[link[num][i]]); func[link[num][i]].del(); } func[num].makereal(cost[num]); } int main() { scanf("%d %d", &n, &m); for(int i=2; i<=n+m; i++){ int k; scanf("%d %lld", &k, &cost[i]); link[k].pb(i); } get_dp(1); while(1){ if(func[1].pq.size()==-func[1].sta)break; func[1].pq.pop(); } func[1].pq.push(0); LL p=0; while(func[1].pq.size()>=2){ p++; LL x=func[1].pq.top(); func[1].pq.pop(); func[1].sty-=(x-func[1].pq.top())*p; } printf("%lld", func[1].sty); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 21496 KB | Output is correct |
2 | Correct | 21 ms | 21496 KB | Output is correct |
3 | Correct | 21 ms | 21496 KB | Output is correct |
4 | Correct | 20 ms | 21496 KB | Output is correct |
5 | Correct | 20 ms | 21496 KB | Output is correct |
6 | Correct | 21 ms | 21496 KB | Output is correct |
7 | Correct | 21 ms | 21496 KB | Output is correct |
8 | Correct | 21 ms | 21496 KB | Output is correct |
9 | Correct | 22 ms | 21496 KB | Output is correct |
10 | Correct | 21 ms | 21416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 21496 KB | Output is correct |
2 | Correct | 22 ms | 21488 KB | Output is correct |
3 | Correct | 22 ms | 21500 KB | Output is correct |
4 | Correct | 22 ms | 21496 KB | Output is correct |
5 | Correct | 21 ms | 21468 KB | Output is correct |
6 | Correct | 21 ms | 21420 KB | Output is correct |
7 | Correct | 22 ms | 21496 KB | Output is correct |
8 | Correct | 10 ms | 21500 KB | Output is correct |
9 | Correct | 21 ms | 21496 KB | Output is correct |
10 | Correct | 22 ms | 21468 KB | Output is correct |
11 | Correct | 22 ms | 21496 KB | Output is correct |
12 | Correct | 23 ms | 21496 KB | Output is correct |
13 | Correct | 21 ms | 21496 KB | Output is correct |
14 | Correct | 22 ms | 21496 KB | Output is correct |
15 | Correct | 21 ms | 21496 KB | Output is correct |
16 | Correct | 21 ms | 21496 KB | Output is correct |
17 | Correct | 21 ms | 21496 KB | Output is correct |
18 | Correct | 21 ms | 21496 KB | Output is correct |
19 | Correct | 22 ms | 21496 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 21496 KB | Output is correct |
2 | Correct | 21 ms | 21496 KB | Output is correct |
3 | Correct | 21 ms | 21496 KB | Output is correct |
4 | Correct | 20 ms | 21496 KB | Output is correct |
5 | Correct | 20 ms | 21496 KB | Output is correct |
6 | Correct | 21 ms | 21496 KB | Output is correct |
7 | Correct | 21 ms | 21496 KB | Output is correct |
8 | Correct | 21 ms | 21496 KB | Output is correct |
9 | Correct | 22 ms | 21496 KB | Output is correct |
10 | Correct | 21 ms | 21416 KB | Output is correct |
11 | Correct | 21 ms | 21496 KB | Output is correct |
12 | Correct | 22 ms | 21488 KB | Output is correct |
13 | Correct | 22 ms | 21500 KB | Output is correct |
14 | Correct | 22 ms | 21496 KB | Output is correct |
15 | Correct | 21 ms | 21468 KB | Output is correct |
16 | Correct | 21 ms | 21420 KB | Output is correct |
17 | Correct | 22 ms | 21496 KB | Output is correct |
18 | Correct | 10 ms | 21500 KB | Output is correct |
19 | Correct | 21 ms | 21496 KB | Output is correct |
20 | Correct | 22 ms | 21468 KB | Output is correct |
21 | Correct | 22 ms | 21496 KB | Output is correct |
22 | Correct | 23 ms | 21496 KB | Output is correct |
23 | Correct | 21 ms | 21496 KB | Output is correct |
24 | Correct | 22 ms | 21496 KB | Output is correct |
25 | Correct | 21 ms | 21496 KB | Output is correct |
26 | Correct | 21 ms | 21496 KB | Output is correct |
27 | Correct | 21 ms | 21496 KB | Output is correct |
28 | Correct | 21 ms | 21496 KB | Output is correct |
29 | Correct | 22 ms | 21496 KB | Output is correct |
30 | Correct | 22 ms | 21496 KB | Output is correct |
31 | Correct | 22 ms | 21496 KB | Output is correct |
32 | Correct | 22 ms | 21624 KB | Output is correct |
33 | Correct | 23 ms | 21624 KB | Output is correct |
34 | Correct | 24 ms | 21624 KB | Output is correct |
35 | Correct | 24 ms | 21756 KB | Output is correct |
36 | Correct | 24 ms | 21724 KB | Output is correct |
37 | Correct | 24 ms | 21812 KB | Output is correct |
38 | Correct | 29 ms | 21828 KB | Output is correct |
39 | Correct | 29 ms | 21752 KB | Output is correct |
40 | Correct | 24 ms | 22520 KB | Output is correct |
41 | Correct | 24 ms | 22496 KB | Output is correct |
42 | Correct | 27 ms | 21752 KB | Output is correct |
43 | Correct | 29 ms | 22140 KB | Output is correct |
44 | Correct | 25 ms | 22008 KB | Output is correct |
45 | Correct | 26 ms | 22008 KB | Output is correct |
46 | Correct | 26 ms | 21752 KB | Output is correct |
47 | Correct | 26 ms | 21972 KB | Output is correct |
48 | Correct | 25 ms | 21880 KB | Output is correct |
49 | Correct | 29 ms | 21920 KB | Output is correct |
50 | Correct | 26 ms | 21752 KB | Output is correct |
51 | Correct | 29 ms | 21752 KB | Output is correct |
52 | Correct | 28 ms | 21844 KB | Output is correct |
53 | Correct | 30 ms | 21880 KB | Output is correct |
54 | Correct | 30 ms | 21880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 21496 KB | Output is correct |
2 | Correct | 21 ms | 21496 KB | Output is correct |
3 | Correct | 21 ms | 21496 KB | Output is correct |
4 | Correct | 20 ms | 21496 KB | Output is correct |
5 | Correct | 20 ms | 21496 KB | Output is correct |
6 | Correct | 21 ms | 21496 KB | Output is correct |
7 | Correct | 21 ms | 21496 KB | Output is correct |
8 | Correct | 21 ms | 21496 KB | Output is correct |
9 | Correct | 22 ms | 21496 KB | Output is correct |
10 | Correct | 21 ms | 21416 KB | Output is correct |
11 | Correct | 21 ms | 21496 KB | Output is correct |
12 | Correct | 22 ms | 21488 KB | Output is correct |
13 | Correct | 22 ms | 21500 KB | Output is correct |
14 | Correct | 22 ms | 21496 KB | Output is correct |
15 | Correct | 21 ms | 21468 KB | Output is correct |
16 | Correct | 21 ms | 21420 KB | Output is correct |
17 | Correct | 22 ms | 21496 KB | Output is correct |
18 | Correct | 10 ms | 21500 KB | Output is correct |
19 | Correct | 21 ms | 21496 KB | Output is correct |
20 | Correct | 22 ms | 21468 KB | Output is correct |
21 | Correct | 22 ms | 21496 KB | Output is correct |
22 | Correct | 23 ms | 21496 KB | Output is correct |
23 | Correct | 21 ms | 21496 KB | Output is correct |
24 | Correct | 22 ms | 21496 KB | Output is correct |
25 | Correct | 21 ms | 21496 KB | Output is correct |
26 | Correct | 21 ms | 21496 KB | Output is correct |
27 | Correct | 21 ms | 21496 KB | Output is correct |
28 | Correct | 21 ms | 21496 KB | Output is correct |
29 | Correct | 22 ms | 21496 KB | Output is correct |
30 | Correct | 22 ms | 21496 KB | Output is correct |
31 | Correct | 22 ms | 21496 KB | Output is correct |
32 | Correct | 22 ms | 21624 KB | Output is correct |
33 | Correct | 23 ms | 21624 KB | Output is correct |
34 | Correct | 24 ms | 21624 KB | Output is correct |
35 | Correct | 24 ms | 21756 KB | Output is correct |
36 | Correct | 24 ms | 21724 KB | Output is correct |
37 | Correct | 24 ms | 21812 KB | Output is correct |
38 | Correct | 29 ms | 21828 KB | Output is correct |
39 | Correct | 29 ms | 21752 KB | Output is correct |
40 | Correct | 24 ms | 22520 KB | Output is correct |
41 | Correct | 24 ms | 22496 KB | Output is correct |
42 | Correct | 27 ms | 21752 KB | Output is correct |
43 | Correct | 29 ms | 22140 KB | Output is correct |
44 | Correct | 25 ms | 22008 KB | Output is correct |
45 | Correct | 26 ms | 22008 KB | Output is correct |
46 | Correct | 26 ms | 21752 KB | Output is correct |
47 | Correct | 26 ms | 21972 KB | Output is correct |
48 | Correct | 25 ms | 21880 KB | Output is correct |
49 | Correct | 29 ms | 21920 KB | Output is correct |
50 | Correct | 26 ms | 21752 KB | Output is correct |
51 | Correct | 29 ms | 21752 KB | Output is correct |
52 | Correct | 28 ms | 21844 KB | Output is correct |
53 | Correct | 30 ms | 21880 KB | Output is correct |
54 | Correct | 30 ms | 21880 KB | Output is correct |
55 | Correct | 32 ms | 22364 KB | Output is correct |
56 | Correct | 65 ms | 24952 KB | Output is correct |
57 | Correct | 106 ms | 27520 KB | Output is correct |
58 | Correct | 134 ms | 29112 KB | Output is correct |
59 | Correct | 180 ms | 31576 KB | Output is correct |
60 | Correct | 275 ms | 33448 KB | Output is correct |
61 | Correct | 251 ms | 35216 KB | Output is correct |
62 | Correct | 282 ms | 36460 KB | Output is correct |
63 | Correct | 358 ms | 38676 KB | Output is correct |
64 | Correct | 346 ms | 38936 KB | Output is correct |
65 | Correct | 188 ms | 82040 KB | Output is correct |
66 | Correct | 187 ms | 82168 KB | Output is correct |
67 | Correct | 187 ms | 35252 KB | Output is correct |
68 | Correct | 259 ms | 60172 KB | Output is correct |
69 | Correct | 340 ms | 56236 KB | Output is correct |
70 | Correct | 313 ms | 56256 KB | Output is correct |
71 | Correct | 290 ms | 50260 KB | Output is correct |
72 | Correct | 291 ms | 50484 KB | Output is correct |
73 | Correct | 274 ms | 47416 KB | Output is correct |
74 | Correct | 278 ms | 47460 KB | Output is correct |
75 | Correct | 264 ms | 46596 KB | Output is correct |
76 | Correct | 263 ms | 46556 KB | Output is correct |
77 | Correct | 270 ms | 45244 KB | Output is correct |
78 | Correct | 266 ms | 42976 KB | Output is correct |
79 | Correct | 276 ms | 45232 KB | Output is correct |