# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110541 | 2019-05-11T06:44:17 Z | Pro_ktmr | Fireworks (APIO16_fireworks) | C++14 | 789 ms | 525312 KB |
#include"bits/stdc++.h" using namespace std; #define LL long long #define PB push_back #define MP make_pair struct f{ LL a=0, b=0; //xが十分に大きいとき、f(x)=ax+b priority_queue<LL> pq; //傾きが1変わる箇所(ダブりあり) void push(LL x){ pq.push(x); pq.push(x); } f operator+(f x){ f ret; ret.a = a + x.a; ret.b = b + x.b; if(pq.size() > x.pq.size()){ ret.pq = pq; while(!x.pq.empty()){ ret.pq.push(x.pq.top()); x.pq.pop(); } } else{ ret.pq = x.pq; while(!pq.empty()){ ret.pq.push(pq.top()); pq.pop(); } } return ret; } }; int N, M, par[300001], C[300001]; f node[300001]; int main(){ scanf("%d%d", &N, &M); for(int i=2; i<=N+M; i++) scanf("%d%d", par+i, C+i); for(int i=N+M; i>N; i--){ node[i].a = 1; node[i].b = -C[i]; node[i].push(C[i]); node[par[i]] = node[par[i]] + node[i]; } for(int i=N; i>1; i--){ while(node[i].a > 1){ //傾きが1より大きい右の方は使わない node[i].a--; node[i].b += node[i].pq.top(); node[i].pq.pop(); } //このノードと親との辺の情報を追加 LL tmp1 = node[i].pq.top(); node[i].pq.pop(); LL tmp0 = node[i].pq.top(); node[i].pq.pop(); node[i].pq.push(tmp0+C[i]); node[i].pq.push(tmp1+C[i]); node[i].b -= C[i]; node[par[i]] = node[par[i]] + node[i]; } while(node[1].a > 0){ //最小のところでは傾きが0 node[1].a--; node[1].b += node[1].pq.top(); node[1].pq.pop(); } printf("%lld\n", node[1].b); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 14464 KB | Output is correct |
2 | Correct | 16 ms | 14464 KB | Output is correct |
3 | Correct | 14 ms | 14464 KB | Output is correct |
4 | Correct | 15 ms | 14464 KB | Output is correct |
5 | Correct | 14 ms | 14464 KB | Output is correct |
6 | Correct | 16 ms | 14464 KB | Output is correct |
7 | Correct | 15 ms | 14436 KB | Output is correct |
8 | Correct | 16 ms | 14464 KB | Output is correct |
9 | Correct | 13 ms | 14436 KB | Output is correct |
10 | Correct | 18 ms | 14448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 14464 KB | Output is correct |
2 | Correct | 15 ms | 14464 KB | Output is correct |
3 | Correct | 15 ms | 14592 KB | Output is correct |
4 | Correct | 14 ms | 14464 KB | Output is correct |
5 | Correct | 15 ms | 14464 KB | Output is correct |
6 | Correct | 15 ms | 14464 KB | Output is correct |
7 | Correct | 17 ms | 14464 KB | Output is correct |
8 | Correct | 16 ms | 14464 KB | Output is correct |
9 | Correct | 15 ms | 14464 KB | Output is correct |
10 | Correct | 17 ms | 14436 KB | Output is correct |
11 | Correct | 15 ms | 14464 KB | Output is correct |
12 | Correct | 19 ms | 14464 KB | Output is correct |
13 | Correct | 17 ms | 14464 KB | Output is correct |
14 | Correct | 15 ms | 14468 KB | Output is correct |
15 | Correct | 14 ms | 14464 KB | Output is correct |
16 | Correct | 15 ms | 14592 KB | Output is correct |
17 | Correct | 15 ms | 14464 KB | Output is correct |
18 | Correct | 17 ms | 14452 KB | Output is correct |
19 | Correct | 14 ms | 14464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 14464 KB | Output is correct |
2 | Correct | 16 ms | 14464 KB | Output is correct |
3 | Correct | 14 ms | 14464 KB | Output is correct |
4 | Correct | 15 ms | 14464 KB | Output is correct |
5 | Correct | 14 ms | 14464 KB | Output is correct |
6 | Correct | 16 ms | 14464 KB | Output is correct |
7 | Correct | 15 ms | 14436 KB | Output is correct |
8 | Correct | 16 ms | 14464 KB | Output is correct |
9 | Correct | 13 ms | 14436 KB | Output is correct |
10 | Correct | 18 ms | 14448 KB | Output is correct |
11 | Correct | 14 ms | 14464 KB | Output is correct |
12 | Correct | 15 ms | 14464 KB | Output is correct |
13 | Correct | 15 ms | 14592 KB | Output is correct |
14 | Correct | 14 ms | 14464 KB | Output is correct |
15 | Correct | 15 ms | 14464 KB | Output is correct |
16 | Correct | 15 ms | 14464 KB | Output is correct |
17 | Correct | 17 ms | 14464 KB | Output is correct |
18 | Correct | 16 ms | 14464 KB | Output is correct |
19 | Correct | 15 ms | 14464 KB | Output is correct |
20 | Correct | 17 ms | 14436 KB | Output is correct |
21 | Correct | 15 ms | 14464 KB | Output is correct |
22 | Correct | 19 ms | 14464 KB | Output is correct |
23 | Correct | 17 ms | 14464 KB | Output is correct |
24 | Correct | 15 ms | 14468 KB | Output is correct |
25 | Correct | 14 ms | 14464 KB | Output is correct |
26 | Correct | 15 ms | 14592 KB | Output is correct |
27 | Correct | 15 ms | 14464 KB | Output is correct |
28 | Correct | 17 ms | 14452 KB | Output is correct |
29 | Correct | 14 ms | 14464 KB | Output is correct |
30 | Correct | 16 ms | 14464 KB | Output is correct |
31 | Correct | 15 ms | 14720 KB | Output is correct |
32 | Correct | 18 ms | 14848 KB | Output is correct |
33 | Correct | 18 ms | 14976 KB | Output is correct |
34 | Correct | 17 ms | 15232 KB | Output is correct |
35 | Correct | 21 ms | 16256 KB | Output is correct |
36 | Correct | 18 ms | 16000 KB | Output is correct |
37 | Correct | 19 ms | 15872 KB | Output is correct |
38 | Correct | 20 ms | 18048 KB | Output is correct |
39 | Correct | 18 ms | 16256 KB | Output is correct |
40 | Correct | 19 ms | 14720 KB | Output is correct |
41 | Correct | 17 ms | 14720 KB | Output is correct |
42 | Correct | 20 ms | 14720 KB | Output is correct |
43 | Correct | 56 ms | 60536 KB | Output is correct |
44 | Correct | 51 ms | 52088 KB | Output is correct |
45 | Correct | 49 ms | 51320 KB | Output is correct |
46 | Correct | 21 ms | 15104 KB | Output is correct |
47 | Correct | 20 ms | 15104 KB | Output is correct |
48 | Correct | 20 ms | 14976 KB | Output is correct |
49 | Correct | 21 ms | 15028 KB | Output is correct |
50 | Correct | 26 ms | 14948 KB | Output is correct |
51 | Correct | 26 ms | 14968 KB | Output is correct |
52 | Correct | 26 ms | 15868 KB | Output is correct |
53 | Correct | 29 ms | 15012 KB | Output is correct |
54 | Correct | 59 ms | 15180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 14464 KB | Output is correct |
2 | Correct | 16 ms | 14464 KB | Output is correct |
3 | Correct | 14 ms | 14464 KB | Output is correct |
4 | Correct | 15 ms | 14464 KB | Output is correct |
5 | Correct | 14 ms | 14464 KB | Output is correct |
6 | Correct | 16 ms | 14464 KB | Output is correct |
7 | Correct | 15 ms | 14436 KB | Output is correct |
8 | Correct | 16 ms | 14464 KB | Output is correct |
9 | Correct | 13 ms | 14436 KB | Output is correct |
10 | Correct | 18 ms | 14448 KB | Output is correct |
11 | Correct | 14 ms | 14464 KB | Output is correct |
12 | Correct | 15 ms | 14464 KB | Output is correct |
13 | Correct | 15 ms | 14592 KB | Output is correct |
14 | Correct | 14 ms | 14464 KB | Output is correct |
15 | Correct | 15 ms | 14464 KB | Output is correct |
16 | Correct | 15 ms | 14464 KB | Output is correct |
17 | Correct | 17 ms | 14464 KB | Output is correct |
18 | Correct | 16 ms | 14464 KB | Output is correct |
19 | Correct | 15 ms | 14464 KB | Output is correct |
20 | Correct | 17 ms | 14436 KB | Output is correct |
21 | Correct | 15 ms | 14464 KB | Output is correct |
22 | Correct | 19 ms | 14464 KB | Output is correct |
23 | Correct | 17 ms | 14464 KB | Output is correct |
24 | Correct | 15 ms | 14468 KB | Output is correct |
25 | Correct | 14 ms | 14464 KB | Output is correct |
26 | Correct | 15 ms | 14592 KB | Output is correct |
27 | Correct | 15 ms | 14464 KB | Output is correct |
28 | Correct | 17 ms | 14452 KB | Output is correct |
29 | Correct | 14 ms | 14464 KB | Output is correct |
30 | Correct | 16 ms | 14464 KB | Output is correct |
31 | Correct | 15 ms | 14720 KB | Output is correct |
32 | Correct | 18 ms | 14848 KB | Output is correct |
33 | Correct | 18 ms | 14976 KB | Output is correct |
34 | Correct | 17 ms | 15232 KB | Output is correct |
35 | Correct | 21 ms | 16256 KB | Output is correct |
36 | Correct | 18 ms | 16000 KB | Output is correct |
37 | Correct | 19 ms | 15872 KB | Output is correct |
38 | Correct | 20 ms | 18048 KB | Output is correct |
39 | Correct | 18 ms | 16256 KB | Output is correct |
40 | Correct | 19 ms | 14720 KB | Output is correct |
41 | Correct | 17 ms | 14720 KB | Output is correct |
42 | Correct | 20 ms | 14720 KB | Output is correct |
43 | Correct | 56 ms | 60536 KB | Output is correct |
44 | Correct | 51 ms | 52088 KB | Output is correct |
45 | Correct | 49 ms | 51320 KB | Output is correct |
46 | Correct | 21 ms | 15104 KB | Output is correct |
47 | Correct | 20 ms | 15104 KB | Output is correct |
48 | Correct | 20 ms | 14976 KB | Output is correct |
49 | Correct | 21 ms | 15028 KB | Output is correct |
50 | Correct | 26 ms | 14948 KB | Output is correct |
51 | Correct | 26 ms | 14968 KB | Output is correct |
52 | Correct | 26 ms | 15868 KB | Output is correct |
53 | Correct | 29 ms | 15012 KB | Output is correct |
54 | Correct | 59 ms | 15180 KB | Output is correct |
55 | Correct | 31 ms | 22884 KB | Output is correct |
56 | Correct | 109 ms | 73312 KB | Output is correct |
57 | Correct | 210 ms | 136976 KB | Output is correct |
58 | Correct | 209 ms | 158316 KB | Output is correct |
59 | Correct | 557 ms | 329312 KB | Output is correct |
60 | Correct | 461 ms | 304964 KB | Output is correct |
61 | Correct | 714 ms | 425924 KB | Output is correct |
62 | Correct | 688 ms | 433028 KB | Output is correct |
63 | Correct | 664 ms | 425212 KB | Output is correct |
64 | Runtime error | 789 ms | 525312 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
65 | Halted | 0 ms | 0 KB | - |