# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113981 | 2019-05-29T12:24:49 Z | patrikpavic2 | Fireworks (APIO16_fireworks) | C++17 | 645 ms | 75768 KB |
#include <cstdio> #include <vector> #include <map> #include <algorithm> #include <set> #define X first #define Y second #define PB push_back using namespace std; typedef long long ll; typedef pair < ll, ll > pll; typedef pair < pll, ll > ppl; typedef vector < int > vi; typedef vector < pll > vl; typedef vector < ll > vll; typedef pair < vll, ll > pvl; const int N = 3e5 + 500; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; vi v[N]; ll tez[N], ans[N], sum[N], ng[N]; multiset < ll > s[N]; int n, m; void f(int x){ if(v[x].size() == 0){ sum[x] = tez[x]; s[x].insert(tez[x]); s[x].insert(tez[x]); ng[x] = -1; return; } ll bs = 0, mini = 0; vll ret; sum[x] = tez[x]; //printf("X = %d\n", x); for(int y : v[x]){ f(y); sum[x] += sum[y]; ng[x] += ng[y]; if(s[x].size() < s[y].size()){ swap(s[x], s[y]); } for(ll a : s[y]) s[x].insert(a); s[y].clear(); } //printf("X = %d NG %d\n", x, ng[x]); while(s[x].size() > 1 - ng[x]) s[x].erase(--s[x].end()); //printf("X = %d\n", x); ll a = *s[x].rbegin(); s[x].erase(s[x].lower_bound(a)); ll b = *s[x].rbegin(); s[x].erase(s[x].lower_bound(b)); //printf("X = %d\n", x); s[x].insert(a + tez[x]); s[x].insert(b + tez[x]); //printf("RET{%d}: ", (int)ret.size()); //for(int xx : s[x]) printf("%d ", xx); //printf("\n"); } int main(){ scanf("%d%d", &n, &m); for(int i = 2;i <= n + m;i++){ int x, y; scanf("%d%d", &x, &y); v[x].PB(i); tez[i] = y; } f(1); ll ans = sum[1], lst = 0, nag = ng[1]; //printf("siz %d\n", s[1].size()); for(ll x : s[1]){ //printf(" %d", x); ans += (x - lst) * nag; nag++; if(!nag) printf("%lld\n", ans); lst = x; } //printf("\n"); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 21504 KB | Output is correct |
2 | Correct | 20 ms | 21504 KB | Output is correct |
3 | Correct | 21 ms | 21504 KB | Output is correct |
4 | Correct | 20 ms | 21504 KB | Output is correct |
5 | Correct | 20 ms | 21504 KB | Output is correct |
6 | Correct | 20 ms | 21504 KB | Output is correct |
7 | Correct | 21 ms | 21504 KB | Output is correct |
8 | Correct | 20 ms | 21632 KB | Output is correct |
9 | Correct | 23 ms | 21504 KB | Output is correct |
10 | Correct | 21 ms | 21504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 21632 KB | Output is correct |
2 | Correct | 20 ms | 21496 KB | Output is correct |
3 | Correct | 20 ms | 21504 KB | Output is correct |
4 | Correct | 20 ms | 21504 KB | Output is correct |
5 | Correct | 20 ms | 21504 KB | Output is correct |
6 | Correct | 19 ms | 21504 KB | Output is correct |
7 | Correct | 19 ms | 21504 KB | Output is correct |
8 | Correct | 20 ms | 21632 KB | Output is correct |
9 | Correct | 19 ms | 21504 KB | Output is correct |
10 | Correct | 19 ms | 21504 KB | Output is correct |
11 | Correct | 19 ms | 21504 KB | Output is correct |
12 | Correct | 20 ms | 21504 KB | Output is correct |
13 | Correct | 19 ms | 21504 KB | Output is correct |
14 | Correct | 19 ms | 21504 KB | Output is correct |
15 | Correct | 19 ms | 21532 KB | Output is correct |
16 | Correct | 19 ms | 21632 KB | Output is correct |
17 | Correct | 20 ms | 21504 KB | Output is correct |
18 | Correct | 19 ms | 21504 KB | Output is correct |
19 | Correct | 20 ms | 21504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 21504 KB | Output is correct |
2 | Correct | 20 ms | 21504 KB | Output is correct |
3 | Correct | 21 ms | 21504 KB | Output is correct |
4 | Correct | 20 ms | 21504 KB | Output is correct |
5 | Correct | 20 ms | 21504 KB | Output is correct |
6 | Correct | 20 ms | 21504 KB | Output is correct |
7 | Correct | 21 ms | 21504 KB | Output is correct |
8 | Correct | 20 ms | 21632 KB | Output is correct |
9 | Correct | 23 ms | 21504 KB | Output is correct |
10 | Correct | 21 ms | 21504 KB | Output is correct |
11 | Correct | 20 ms | 21632 KB | Output is correct |
12 | Correct | 20 ms | 21496 KB | Output is correct |
13 | Correct | 20 ms | 21504 KB | Output is correct |
14 | Correct | 20 ms | 21504 KB | Output is correct |
15 | Correct | 20 ms | 21504 KB | Output is correct |
16 | Correct | 19 ms | 21504 KB | Output is correct |
17 | Correct | 19 ms | 21504 KB | Output is correct |
18 | Correct | 20 ms | 21632 KB | Output is correct |
19 | Correct | 19 ms | 21504 KB | Output is correct |
20 | Correct | 19 ms | 21504 KB | Output is correct |
21 | Correct | 19 ms | 21504 KB | Output is correct |
22 | Correct | 20 ms | 21504 KB | Output is correct |
23 | Correct | 19 ms | 21504 KB | Output is correct |
24 | Correct | 19 ms | 21504 KB | Output is correct |
25 | Correct | 19 ms | 21532 KB | Output is correct |
26 | Correct | 19 ms | 21632 KB | Output is correct |
27 | Correct | 20 ms | 21504 KB | Output is correct |
28 | Correct | 19 ms | 21504 KB | Output is correct |
29 | Correct | 20 ms | 21504 KB | Output is correct |
30 | Correct | 20 ms | 21504 KB | Output is correct |
31 | Correct | 21 ms | 21632 KB | Output is correct |
32 | Correct | 22 ms | 21632 KB | Output is correct |
33 | Correct | 22 ms | 21752 KB | Output is correct |
34 | Correct | 21 ms | 21760 KB | Output is correct |
35 | Correct | 22 ms | 21760 KB | Output is correct |
36 | Correct | 23 ms | 21760 KB | Output is correct |
37 | Correct | 24 ms | 21888 KB | Output is correct |
38 | Correct | 23 ms | 22016 KB | Output is correct |
39 | Correct | 24 ms | 21888 KB | Output is correct |
40 | Correct | 22 ms | 22400 KB | Output is correct |
41 | Correct | 23 ms | 22400 KB | Output is correct |
42 | Correct | 23 ms | 21888 KB | Output is correct |
43 | Correct | 23 ms | 22272 KB | Output is correct |
44 | Correct | 23 ms | 22144 KB | Output is correct |
45 | Correct | 24 ms | 22016 KB | Output is correct |
46 | Correct | 24 ms | 22008 KB | Output is correct |
47 | Correct | 24 ms | 22016 KB | Output is correct |
48 | Correct | 23 ms | 21888 KB | Output is correct |
49 | Correct | 24 ms | 21988 KB | Output is correct |
50 | Correct | 23 ms | 22016 KB | Output is correct |
51 | Correct | 23 ms | 22136 KB | Output is correct |
52 | Correct | 23 ms | 21944 KB | Output is correct |
53 | Correct | 23 ms | 22016 KB | Output is correct |
54 | Correct | 24 ms | 22144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 21504 KB | Output is correct |
2 | Correct | 20 ms | 21504 KB | Output is correct |
3 | Correct | 21 ms | 21504 KB | Output is correct |
4 | Correct | 20 ms | 21504 KB | Output is correct |
5 | Correct | 20 ms | 21504 KB | Output is correct |
6 | Correct | 20 ms | 21504 KB | Output is correct |
7 | Correct | 21 ms | 21504 KB | Output is correct |
8 | Correct | 20 ms | 21632 KB | Output is correct |
9 | Correct | 23 ms | 21504 KB | Output is correct |
10 | Correct | 21 ms | 21504 KB | Output is correct |
11 | Correct | 20 ms | 21632 KB | Output is correct |
12 | Correct | 20 ms | 21496 KB | Output is correct |
13 | Correct | 20 ms | 21504 KB | Output is correct |
14 | Correct | 20 ms | 21504 KB | Output is correct |
15 | Correct | 20 ms | 21504 KB | Output is correct |
16 | Correct | 19 ms | 21504 KB | Output is correct |
17 | Correct | 19 ms | 21504 KB | Output is correct |
18 | Correct | 20 ms | 21632 KB | Output is correct |
19 | Correct | 19 ms | 21504 KB | Output is correct |
20 | Correct | 19 ms | 21504 KB | Output is correct |
21 | Correct | 19 ms | 21504 KB | Output is correct |
22 | Correct | 20 ms | 21504 KB | Output is correct |
23 | Correct | 19 ms | 21504 KB | Output is correct |
24 | Correct | 19 ms | 21504 KB | Output is correct |
25 | Correct | 19 ms | 21532 KB | Output is correct |
26 | Correct | 19 ms | 21632 KB | Output is correct |
27 | Correct | 20 ms | 21504 KB | Output is correct |
28 | Correct | 19 ms | 21504 KB | Output is correct |
29 | Correct | 20 ms | 21504 KB | Output is correct |
30 | Correct | 20 ms | 21504 KB | Output is correct |
31 | Correct | 21 ms | 21632 KB | Output is correct |
32 | Correct | 22 ms | 21632 KB | Output is correct |
33 | Correct | 22 ms | 21752 KB | Output is correct |
34 | Correct | 21 ms | 21760 KB | Output is correct |
35 | Correct | 22 ms | 21760 KB | Output is correct |
36 | Correct | 23 ms | 21760 KB | Output is correct |
37 | Correct | 24 ms | 21888 KB | Output is correct |
38 | Correct | 23 ms | 22016 KB | Output is correct |
39 | Correct | 24 ms | 21888 KB | Output is correct |
40 | Correct | 22 ms | 22400 KB | Output is correct |
41 | Correct | 23 ms | 22400 KB | Output is correct |
42 | Correct | 23 ms | 21888 KB | Output is correct |
43 | Correct | 23 ms | 22272 KB | Output is correct |
44 | Correct | 23 ms | 22144 KB | Output is correct |
45 | Correct | 24 ms | 22016 KB | Output is correct |
46 | Correct | 24 ms | 22008 KB | Output is correct |
47 | Correct | 24 ms | 22016 KB | Output is correct |
48 | Correct | 23 ms | 21888 KB | Output is correct |
49 | Correct | 24 ms | 21988 KB | Output is correct |
50 | Correct | 23 ms | 22016 KB | Output is correct |
51 | Correct | 23 ms | 22136 KB | Output is correct |
52 | Correct | 23 ms | 21944 KB | Output is correct |
53 | Correct | 23 ms | 22016 KB | Output is correct |
54 | Correct | 24 ms | 22144 KB | Output is correct |
55 | Correct | 31 ms | 22520 KB | Output is correct |
56 | Correct | 72 ms | 25208 KB | Output is correct |
57 | Correct | 119 ms | 27996 KB | Output is correct |
58 | Correct | 148 ms | 30008 KB | Output is correct |
59 | Correct | 215 ms | 33064 KB | Output is correct |
60 | Correct | 259 ms | 35576 KB | Output is correct |
61 | Correct | 309 ms | 37816 KB | Output is correct |
62 | Correct | 353 ms | 40056 KB | Output is correct |
63 | Correct | 384 ms | 43412 KB | Output is correct |
64 | Correct | 399 ms | 43768 KB | Output is correct |
65 | Correct | 175 ms | 75768 KB | Output is correct |
66 | Correct | 175 ms | 75640 KB | Output is correct |
67 | Correct | 227 ms | 43000 KB | Output is correct |
68 | Correct | 331 ms | 61556 KB | Output is correct |
69 | Correct | 403 ms | 58872 KB | Output is correct |
70 | Correct | 373 ms | 58748 KB | Output is correct |
71 | Correct | 454 ms | 48732 KB | Output is correct |
72 | Correct | 455 ms | 48888 KB | Output is correct |
73 | Correct | 458 ms | 48376 KB | Output is correct |
74 | Correct | 458 ms | 48376 KB | Output is correct |
75 | Correct | 467 ms | 48168 KB | Output is correct |
76 | Correct | 455 ms | 48120 KB | Output is correct |
77 | Correct | 504 ms | 48172 KB | Output is correct |
78 | Correct | 539 ms | 48636 KB | Output is correct |
79 | Correct | 645 ms | 61372 KB | Output is correct |