# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
154097 | 2019-09-18T11:10:26 Z | arnold518 | Fireworks (APIO16_fireworks) | C++14 | 319 ms | 74492 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 3e5; int N, M, C[MAXN+10]; vector<int> adj[MAXN+10]; ll ans=1e18; struct Func { ll slope, cut; priority_queue<ll> PQ; Func() : slope(0), cut(0) {} void propa(ll x) { int i, j; ll a, b; while(!PQ.empty() && slope+(int)PQ.size()>-1) { if(slope+PQ.size()==0) a=PQ.top(); if(slope+PQ.size()==1) b=PQ.top(); PQ.pop(); } PQ.push(a+x); PQ.push(b+x); cut+=x; } }; Func *dfs(int now) { int i, j; Func *ret=new Func; if(adj[now].empty()) { ret->slope=-1; ret->cut=C[now]; ret->PQ.push(C[now]); ret->PQ.push(C[now]); return ret; } for(int nxt : adj[now]) { Func *t=dfs(nxt); if(t->PQ.size()>ret->PQ.size()) swap(t, ret); ret->slope+=t->slope; ret->cut+=t->cut; while(!t->PQ.empty()) ret->PQ.push(t->PQ.top()), t->PQ.pop(); } if(now!=1) ret->propa(C[now]); return ret; } int main() { int i, j; scanf("%d%d", &N, &M); for(i=2; i<=N+M; i++) { int p; scanf("%d%d", &p, &C[i]); adj[p].push_back(i); } Func *fin=dfs(1); vector<ll> V; while(!fin->PQ.empty()) V.push_back(fin->PQ.top()), fin->PQ.pop(); V.push_back(0); reverse(V.begin(), V.end()); for(i=1; i<V.size(); i++) { ans=min(ans, fin->cut+fin->slope*(V[i]-V[i-1])); fin->cut+=fin->slope*(V[i]-V[i-1]); fin->slope++; } printf("%lld", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 7416 KB | Output is correct |
2 | Correct | 10 ms | 7416 KB | Output is correct |
3 | Correct | 10 ms | 7416 KB | Output is correct |
4 | Correct | 10 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7420 KB | Output is correct |
6 | Correct | 11 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 8 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 9 ms | 7416 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7288 KB | Output is correct |
2 | Correct | 9 ms | 7416 KB | Output is correct |
3 | Correct | 10 ms | 7416 KB | Output is correct |
4 | Correct | 8 ms | 7420 KB | Output is correct |
5 | Correct | 8 ms | 7416 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 10 ms | 7416 KB | Output is correct |
9 | Correct | 10 ms | 7416 KB | Output is correct |
10 | Correct | 10 ms | 7420 KB | Output is correct |
11 | Correct | 10 ms | 7416 KB | Output is correct |
12 | Correct | 9 ms | 7416 KB | Output is correct |
13 | Correct | 9 ms | 7420 KB | Output is correct |
14 | Correct | 9 ms | 7416 KB | Output is correct |
15 | Correct | 9 ms | 7416 KB | Output is correct |
16 | Correct | 9 ms | 7416 KB | Output is correct |
17 | Correct | 8 ms | 7420 KB | Output is correct |
18 | Correct | 9 ms | 7416 KB | Output is correct |
19 | Correct | 9 ms | 7416 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 7416 KB | Output is correct |
2 | Correct | 10 ms | 7416 KB | Output is correct |
3 | Correct | 10 ms | 7416 KB | Output is correct |
4 | Correct | 10 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7420 KB | Output is correct |
6 | Correct | 11 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 8 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 9 ms | 7416 KB | Output is correct |
11 | Correct | 9 ms | 7288 KB | Output is correct |
12 | Correct | 9 ms | 7416 KB | Output is correct |
13 | Correct | 10 ms | 7416 KB | Output is correct |
14 | Correct | 8 ms | 7420 KB | Output is correct |
15 | Correct | 8 ms | 7416 KB | Output is correct |
16 | Correct | 9 ms | 7416 KB | Output is correct |
17 | Correct | 9 ms | 7416 KB | Output is correct |
18 | Correct | 10 ms | 7416 KB | Output is correct |
19 | Correct | 10 ms | 7416 KB | Output is correct |
20 | Correct | 10 ms | 7420 KB | Output is correct |
21 | Correct | 10 ms | 7416 KB | Output is correct |
22 | Correct | 9 ms | 7416 KB | Output is correct |
23 | Correct | 9 ms | 7420 KB | Output is correct |
24 | Correct | 9 ms | 7416 KB | Output is correct |
25 | Correct | 9 ms | 7416 KB | Output is correct |
26 | Correct | 9 ms | 7416 KB | Output is correct |
27 | Correct | 8 ms | 7420 KB | Output is correct |
28 | Correct | 9 ms | 7416 KB | Output is correct |
29 | Correct | 9 ms | 7416 KB | Output is correct |
30 | Correct | 9 ms | 7416 KB | Output is correct |
31 | Correct | 9 ms | 7544 KB | Output is correct |
32 | Correct | 10 ms | 7544 KB | Output is correct |
33 | Correct | 11 ms | 7672 KB | Output is correct |
34 | Correct | 12 ms | 7800 KB | Output is correct |
35 | Correct | 12 ms | 7800 KB | Output is correct |
36 | Correct | 12 ms | 7928 KB | Output is correct |
37 | Correct | 13 ms | 7928 KB | Output is correct |
38 | Correct | 12 ms | 8056 KB | Output is correct |
39 | Correct | 14 ms | 7980 KB | Output is correct |
40 | Correct | 14 ms | 8440 KB | Output is correct |
41 | Correct | 12 ms | 8472 KB | Output is correct |
42 | Correct | 13 ms | 7928 KB | Output is correct |
43 | Correct | 13 ms | 8184 KB | Output is correct |
44 | Correct | 13 ms | 8184 KB | Output is correct |
45 | Correct | 15 ms | 8184 KB | Output is correct |
46 | Correct | 13 ms | 8312 KB | Output is correct |
47 | Correct | 13 ms | 8184 KB | Output is correct |
48 | Correct | 14 ms | 8056 KB | Output is correct |
49 | Correct | 13 ms | 8184 KB | Output is correct |
50 | Correct | 14 ms | 8056 KB | Output is correct |
51 | Correct | 12 ms | 7928 KB | Output is correct |
52 | Correct | 13 ms | 8056 KB | Output is correct |
53 | Correct | 13 ms | 8056 KB | Output is correct |
54 | Correct | 13 ms | 8264 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 7416 KB | Output is correct |
2 | Correct | 10 ms | 7416 KB | Output is correct |
3 | Correct | 10 ms | 7416 KB | Output is correct |
4 | Correct | 10 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7420 KB | Output is correct |
6 | Correct | 11 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 8 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 9 ms | 7416 KB | Output is correct |
11 | Correct | 9 ms | 7288 KB | Output is correct |
12 | Correct | 9 ms | 7416 KB | Output is correct |
13 | Correct | 10 ms | 7416 KB | Output is correct |
14 | Correct | 8 ms | 7420 KB | Output is correct |
15 | Correct | 8 ms | 7416 KB | Output is correct |
16 | Correct | 9 ms | 7416 KB | Output is correct |
17 | Correct | 9 ms | 7416 KB | Output is correct |
18 | Correct | 10 ms | 7416 KB | Output is correct |
19 | Correct | 10 ms | 7416 KB | Output is correct |
20 | Correct | 10 ms | 7420 KB | Output is correct |
21 | Correct | 10 ms | 7416 KB | Output is correct |
22 | Correct | 9 ms | 7416 KB | Output is correct |
23 | Correct | 9 ms | 7420 KB | Output is correct |
24 | Correct | 9 ms | 7416 KB | Output is correct |
25 | Correct | 9 ms | 7416 KB | Output is correct |
26 | Correct | 9 ms | 7416 KB | Output is correct |
27 | Correct | 8 ms | 7420 KB | Output is correct |
28 | Correct | 9 ms | 7416 KB | Output is correct |
29 | Correct | 9 ms | 7416 KB | Output is correct |
30 | Correct | 9 ms | 7416 KB | Output is correct |
31 | Correct | 9 ms | 7544 KB | Output is correct |
32 | Correct | 10 ms | 7544 KB | Output is correct |
33 | Correct | 11 ms | 7672 KB | Output is correct |
34 | Correct | 12 ms | 7800 KB | Output is correct |
35 | Correct | 12 ms | 7800 KB | Output is correct |
36 | Correct | 12 ms | 7928 KB | Output is correct |
37 | Correct | 13 ms | 7928 KB | Output is correct |
38 | Correct | 12 ms | 8056 KB | Output is correct |
39 | Correct | 14 ms | 7980 KB | Output is correct |
40 | Correct | 14 ms | 8440 KB | Output is correct |
41 | Correct | 12 ms | 8472 KB | Output is correct |
42 | Correct | 13 ms | 7928 KB | Output is correct |
43 | Correct | 13 ms | 8184 KB | Output is correct |
44 | Correct | 13 ms | 8184 KB | Output is correct |
45 | Correct | 15 ms | 8184 KB | Output is correct |
46 | Correct | 13 ms | 8312 KB | Output is correct |
47 | Correct | 13 ms | 8184 KB | Output is correct |
48 | Correct | 14 ms | 8056 KB | Output is correct |
49 | Correct | 13 ms | 8184 KB | Output is correct |
50 | Correct | 14 ms | 8056 KB | Output is correct |
51 | Correct | 12 ms | 7928 KB | Output is correct |
52 | Correct | 13 ms | 8056 KB | Output is correct |
53 | Correct | 13 ms | 8056 KB | Output is correct |
54 | Correct | 13 ms | 8264 KB | Output is correct |
55 | Correct | 21 ms | 9080 KB | Output is correct |
56 | Correct | 59 ms | 14092 KB | Output is correct |
57 | Correct | 105 ms | 18736 KB | Output is correct |
58 | Correct | 122 ms | 22000 KB | Output is correct |
59 | Correct | 156 ms | 26608 KB | Output is correct |
60 | Correct | 190 ms | 31092 KB | Output is correct |
61 | Correct | 227 ms | 35128 KB | Output is correct |
62 | Correct | 253 ms | 37868 KB | Output is correct |
63 | Correct | 304 ms | 43628 KB | Output is correct |
64 | Correct | 319 ms | 45420 KB | Output is correct |
65 | Correct | 178 ms | 74492 KB | Output is correct |
66 | Correct | 177 ms | 74444 KB | Output is correct |
67 | Correct | 200 ms | 41848 KB | Output is correct |
68 | Correct | 257 ms | 62120 KB | Output is correct |
69 | Correct | 295 ms | 59492 KB | Output is correct |
70 | Correct | 299 ms | 59556 KB | Output is correct |
71 | Correct | 299 ms | 60384 KB | Output is correct |
72 | Correct | 296 ms | 60388 KB | Output is correct |
73 | Correct | 287 ms | 56932 KB | Output is correct |
74 | Correct | 273 ms | 56924 KB | Output is correct |
75 | Correct | 283 ms | 55552 KB | Output is correct |
76 | Correct | 278 ms | 55808 KB | Output is correct |
77 | Correct | 290 ms | 54240 KB | Output is correct |
78 | Correct | 278 ms | 53212 KB | Output is correct |
79 | Correct | 310 ms | 58324 KB | Output is correct |