# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
110548 | 2019-05-11T06:52:33 Z | Pro_ktmr | Fireworks (APIO16_fireworks) | C++14 | 327 ms | 51284 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); } void clear(){ while(!pq->empty()) pq->pop(); } 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=1; i<=N+M; i++) node[i].pq = new priority_queue<long long>; 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]; //node[i].clear(); } 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]; //node[i].clear(); } 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 7 ms | 7424 KB | Output is correct |
3 | Correct | 8 ms | 7424 KB | Output is correct |
4 | Correct | 7 ms | 7424 KB | Output is correct |
5 | Correct | 8 ms | 7424 KB | Output is correct |
6 | Correct | 7 ms | 7424 KB | Output is correct |
7 | Correct | 7 ms | 7424 KB | Output is correct |
8 | Correct | 7 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 7424 KB | Output is correct |
2 | Correct | 8 ms | 7424 KB | Output is correct |
3 | Correct | 8 ms | 7424 KB | Output is correct |
4 | Correct | 8 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7396 KB | Output is correct |
6 | Correct | 8 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 10 ms | 7424 KB | Output is correct |
9 | Correct | 7 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
11 | Correct | 8 ms | 7424 KB | Output is correct |
12 | Correct | 8 ms | 7424 KB | Output is correct |
13 | Correct | 8 ms | 7424 KB | Output is correct |
14 | Correct | 8 ms | 7424 KB | Output is correct |
15 | Correct | 8 ms | 7424 KB | Output is correct |
16 | Correct | 37 ms | 7424 KB | Output is correct |
17 | Correct | 8 ms | 7552 KB | Output is correct |
18 | Correct | 9 ms | 7424 KB | Output is correct |
19 | Correct | 8 ms | 7424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 7 ms | 7424 KB | Output is correct |
3 | Correct | 8 ms | 7424 KB | Output is correct |
4 | Correct | 7 ms | 7424 KB | Output is correct |
5 | Correct | 8 ms | 7424 KB | Output is correct |
6 | Correct | 7 ms | 7424 KB | Output is correct |
7 | Correct | 7 ms | 7424 KB | Output is correct |
8 | Correct | 7 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
11 | Correct | 7 ms | 7424 KB | Output is correct |
12 | Correct | 8 ms | 7424 KB | Output is correct |
13 | Correct | 8 ms | 7424 KB | Output is correct |
14 | Correct | 8 ms | 7424 KB | Output is correct |
15 | Correct | 9 ms | 7396 KB | Output is correct |
16 | Correct | 8 ms | 7424 KB | Output is correct |
17 | Correct | 9 ms | 7424 KB | Output is correct |
18 | Correct | 10 ms | 7424 KB | Output is correct |
19 | Correct | 7 ms | 7424 KB | Output is correct |
20 | Correct | 9 ms | 7424 KB | Output is correct |
21 | Correct | 8 ms | 7424 KB | Output is correct |
22 | Correct | 8 ms | 7424 KB | Output is correct |
23 | Correct | 8 ms | 7424 KB | Output is correct |
24 | Correct | 8 ms | 7424 KB | Output is correct |
25 | Correct | 8 ms | 7424 KB | Output is correct |
26 | Correct | 37 ms | 7424 KB | Output is correct |
27 | Correct | 8 ms | 7552 KB | Output is correct |
28 | Correct | 9 ms | 7424 KB | Output is correct |
29 | Correct | 8 ms | 7424 KB | Output is correct |
30 | Correct | 10 ms | 7424 KB | Output is correct |
31 | Correct | 9 ms | 7424 KB | Output is correct |
32 | Correct | 8 ms | 7552 KB | Output is correct |
33 | Correct | 9 ms | 7552 KB | Output is correct |
34 | Correct | 9 ms | 7680 KB | Output is correct |
35 | Correct | 9 ms | 7680 KB | Output is correct |
36 | Correct | 10 ms | 7808 KB | Output is correct |
37 | Correct | 11 ms | 7808 KB | Output is correct |
38 | Correct | 10 ms | 7808 KB | Output is correct |
39 | Correct | 9 ms | 7808 KB | Output is correct |
40 | Correct | 9 ms | 7680 KB | Output is correct |
41 | Correct | 8 ms | 7680 KB | Output is correct |
42 | Correct | 11 ms | 7680 KB | Output is correct |
43 | Correct | 10 ms | 7808 KB | Output is correct |
44 | Correct | 11 ms | 7808 KB | Output is correct |
45 | Correct | 11 ms | 7808 KB | Output is correct |
46 | Correct | 11 ms | 8064 KB | Output is correct |
47 | Correct | 13 ms | 8064 KB | Output is correct |
48 | Correct | 11 ms | 7936 KB | Output is correct |
49 | Correct | 11 ms | 7936 KB | Output is correct |
50 | Correct | 10 ms | 7936 KB | Output is correct |
51 | Correct | 10 ms | 7808 KB | Output is correct |
52 | Correct | 12 ms | 7936 KB | Output is correct |
53 | Correct | 10 ms | 7908 KB | Output is correct |
54 | Correct | 12 ms | 7936 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 7 ms | 7424 KB | Output is correct |
3 | Correct | 8 ms | 7424 KB | Output is correct |
4 | Correct | 7 ms | 7424 KB | Output is correct |
5 | Correct | 8 ms | 7424 KB | Output is correct |
6 | Correct | 7 ms | 7424 KB | Output is correct |
7 | Correct | 7 ms | 7424 KB | Output is correct |
8 | Correct | 7 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7424 KB | Output is correct |
11 | Correct | 7 ms | 7424 KB | Output is correct |
12 | Correct | 8 ms | 7424 KB | Output is correct |
13 | Correct | 8 ms | 7424 KB | Output is correct |
14 | Correct | 8 ms | 7424 KB | Output is correct |
15 | Correct | 9 ms | 7396 KB | Output is correct |
16 | Correct | 8 ms | 7424 KB | Output is correct |
17 | Correct | 9 ms | 7424 KB | Output is correct |
18 | Correct | 10 ms | 7424 KB | Output is correct |
19 | Correct | 7 ms | 7424 KB | Output is correct |
20 | Correct | 9 ms | 7424 KB | Output is correct |
21 | Correct | 8 ms | 7424 KB | Output is correct |
22 | Correct | 8 ms | 7424 KB | Output is correct |
23 | Correct | 8 ms | 7424 KB | Output is correct |
24 | Correct | 8 ms | 7424 KB | Output is correct |
25 | Correct | 8 ms | 7424 KB | Output is correct |
26 | Correct | 37 ms | 7424 KB | Output is correct |
27 | Correct | 8 ms | 7552 KB | Output is correct |
28 | Correct | 9 ms | 7424 KB | Output is correct |
29 | Correct | 8 ms | 7424 KB | Output is correct |
30 | Correct | 10 ms | 7424 KB | Output is correct |
31 | Correct | 9 ms | 7424 KB | Output is correct |
32 | Correct | 8 ms | 7552 KB | Output is correct |
33 | Correct | 9 ms | 7552 KB | Output is correct |
34 | Correct | 9 ms | 7680 KB | Output is correct |
35 | Correct | 9 ms | 7680 KB | Output is correct |
36 | Correct | 10 ms | 7808 KB | Output is correct |
37 | Correct | 11 ms | 7808 KB | Output is correct |
38 | Correct | 10 ms | 7808 KB | Output is correct |
39 | Correct | 9 ms | 7808 KB | Output is correct |
40 | Correct | 9 ms | 7680 KB | Output is correct |
41 | Correct | 8 ms | 7680 KB | Output is correct |
42 | Correct | 11 ms | 7680 KB | Output is correct |
43 | Correct | 10 ms | 7808 KB | Output is correct |
44 | Correct | 11 ms | 7808 KB | Output is correct |
45 | Correct | 11 ms | 7808 KB | Output is correct |
46 | Correct | 11 ms | 8064 KB | Output is correct |
47 | Correct | 13 ms | 8064 KB | Output is correct |
48 | Correct | 11 ms | 7936 KB | Output is correct |
49 | Correct | 11 ms | 7936 KB | Output is correct |
50 | Correct | 10 ms | 7936 KB | Output is correct |
51 | Correct | 10 ms | 7808 KB | Output is correct |
52 | Correct | 12 ms | 7936 KB | Output is correct |
53 | Correct | 10 ms | 7908 KB | Output is correct |
54 | Correct | 12 ms | 7936 KB | Output is correct |
55 | Correct | 19 ms | 8576 KB | Output is correct |
56 | Correct | 49 ms | 11960 KB | Output is correct |
57 | Correct | 70 ms | 15096 KB | Output is correct |
58 | Correct | 93 ms | 17208 KB | Output is correct |
59 | Correct | 124 ms | 20464 KB | Output is correct |
60 | Correct | 189 ms | 24020 KB | Output is correct |
61 | Correct | 172 ms | 26344 KB | Output is correct |
62 | Correct | 192 ms | 28244 KB | Output is correct |
63 | Correct | 272 ms | 32100 KB | Output is correct |
64 | Correct | 256 ms | 37328 KB | Output is correct |
65 | Correct | 132 ms | 28664 KB | Output is correct |
66 | Correct | 116 ms | 28664 KB | Output is correct |
67 | Correct | 111 ms | 28792 KB | Output is correct |
68 | Correct | 160 ms | 35488 KB | Output is correct |
69 | Correct | 208 ms | 36040 KB | Output is correct |
70 | Correct | 216 ms | 36076 KB | Output is correct |
71 | Correct | 327 ms | 51284 KB | Output is correct |
72 | Correct | 281 ms | 51212 KB | Output is correct |
73 | Correct | 212 ms | 47460 KB | Output is correct |
74 | Correct | 242 ms | 48136 KB | Output is correct |
75 | Correct | 243 ms | 46280 KB | Output is correct |
76 | Correct | 222 ms | 46456 KB | Output is correct |
77 | Correct | 229 ms | 45536 KB | Output is correct |
78 | Correct | 233 ms | 45156 KB | Output is correct |
79 | Correct | 244 ms | 43724 KB | Output is correct |