# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
934647 | 2024-02-27T18:33:53 Z | LaviniaTornaghi | Fireworks (APIO16_fireworks) | C++14 | 310 ms | 58376 KB |
#include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; typedef long long i64; typedef __gnu_pbds::priority_queue<i64> pairing_heap; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M; cin >> N >> M; vector<vector<int>> adj(N); vector<int> t(N + M); for (int i = 1; i < N + M; i++) { int p; cin >> p >> t[i]; adj[p - 1].push_back(i); } auto dfs = [&](auto &&dfs, int node) { pairing_heap q; if (node >= N) { q.push(t[node]); q.push(t[node]); return q; } for (auto child: adj[node]) { pairing_heap cq = dfs(dfs, child); q.join(cq); } for (int i = 0; i < adj[node].size() - 1; i++) q.pop(); i64 x1 = q.top(); q.pop(); i64 x0 = q.top(); q.pop(); q.push(x0 + t[node]); q.push(x1 + t[node]); return q; }; pairing_heap q = dfs(dfs, 0); vector<i64> slope_changes; while (!q.empty()) { i64 x = q.top(); q.pop(); slope_changes.push_back(x); } reverse(slope_changes.begin(), slope_changes.end()); int curr_slope = 1 - (int)slope_changes.size(); i64 last_point = 0; i64 curr_value = accumulate(t.begin(), t.end(), 0LL); i64 best_value = curr_value; for (auto x: slope_changes) { curr_value += curr_slope * (x - last_point); best_value = min(best_value, curr_value); last_point = x; curr_slope++; } cout << best_value << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 448 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 460 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 456 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 452 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 600 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 448 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 460 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 456 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 452 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 0 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 0 ms | 348 KB | Output is correct |
27 | Correct | 1 ms | 600 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 348 KB | Output is correct |
31 | Correct | 1 ms | 360 KB | Output is correct |
32 | Correct | 1 ms | 348 KB | Output is correct |
33 | Correct | 1 ms | 600 KB | Output is correct |
34 | Correct | 1 ms | 604 KB | Output is correct |
35 | Correct | 1 ms | 856 KB | Output is correct |
36 | Correct | 2 ms | 604 KB | Output is correct |
37 | Correct | 2 ms | 604 KB | Output is correct |
38 | Correct | 2 ms | 860 KB | Output is correct |
39 | Correct | 2 ms | 604 KB | Output is correct |
40 | Correct | 2 ms | 1372 KB | Output is correct |
41 | Correct | 2 ms | 1372 KB | Output is correct |
42 | Correct | 2 ms | 604 KB | Output is correct |
43 | Correct | 2 ms | 1112 KB | Output is correct |
44 | Correct | 3 ms | 860 KB | Output is correct |
45 | Correct | 2 ms | 860 KB | Output is correct |
46 | Correct | 3 ms | 812 KB | Output is correct |
47 | Correct | 3 ms | 724 KB | Output is correct |
48 | Correct | 2 ms | 860 KB | Output is correct |
49 | Correct | 2 ms | 724 KB | Output is correct |
50 | Correct | 2 ms | 860 KB | Output is correct |
51 | Correct | 2 ms | 860 KB | Output is correct |
52 | Correct | 2 ms | 860 KB | Output is correct |
53 | Correct | 2 ms | 860 KB | Output is correct |
54 | Correct | 2 ms | 1116 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 448 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 460 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 456 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 452 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 0 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 0 ms | 348 KB | Output is correct |
27 | Correct | 1 ms | 600 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 348 KB | Output is correct |
31 | Correct | 1 ms | 360 KB | Output is correct |
32 | Correct | 1 ms | 348 KB | Output is correct |
33 | Correct | 1 ms | 600 KB | Output is correct |
34 | Correct | 1 ms | 604 KB | Output is correct |
35 | Correct | 1 ms | 856 KB | Output is correct |
36 | Correct | 2 ms | 604 KB | Output is correct |
37 | Correct | 2 ms | 604 KB | Output is correct |
38 | Correct | 2 ms | 860 KB | Output is correct |
39 | Correct | 2 ms | 604 KB | Output is correct |
40 | Correct | 2 ms | 1372 KB | Output is correct |
41 | Correct | 2 ms | 1372 KB | Output is correct |
42 | Correct | 2 ms | 604 KB | Output is correct |
43 | Correct | 2 ms | 1112 KB | Output is correct |
44 | Correct | 3 ms | 860 KB | Output is correct |
45 | Correct | 2 ms | 860 KB | Output is correct |
46 | Correct | 3 ms | 812 KB | Output is correct |
47 | Correct | 3 ms | 724 KB | Output is correct |
48 | Correct | 2 ms | 860 KB | Output is correct |
49 | Correct | 2 ms | 724 KB | Output is correct |
50 | Correct | 2 ms | 860 KB | Output is correct |
51 | Correct | 2 ms | 860 KB | Output is correct |
52 | Correct | 2 ms | 860 KB | Output is correct |
53 | Correct | 2 ms | 860 KB | Output is correct |
54 | Correct | 2 ms | 1116 KB | Output is correct |
55 | Correct | 5 ms | 1484 KB | Output is correct |
56 | Correct | 20 ms | 4088 KB | Output is correct |
57 | Correct | 28 ms | 6612 KB | Output is correct |
58 | Correct | 35 ms | 8160 KB | Output is correct |
59 | Correct | 47 ms | 10452 KB | Output is correct |
60 | Correct | 71 ms | 12460 KB | Output is correct |
61 | Correct | 89 ms | 14652 KB | Output is correct |
62 | Correct | 90 ms | 16044 KB | Output is correct |
63 | Correct | 97 ms | 18896 KB | Output is correct |
64 | Correct | 133 ms | 19920 KB | Output is correct |
65 | Correct | 88 ms | 58344 KB | Output is correct |
66 | Correct | 87 ms | 58376 KB | Output is correct |
67 | Correct | 73 ms | 20904 KB | Output is correct |
68 | Correct | 112 ms | 40392 KB | Output is correct |
69 | Correct | 132 ms | 37320 KB | Output is correct |
70 | Correct | 129 ms | 37064 KB | Output is correct |
71 | Correct | 172 ms | 24648 KB | Output is correct |
72 | Correct | 149 ms | 24028 KB | Output is correct |
73 | Correct | 159 ms | 24460 KB | Output is correct |
74 | Correct | 165 ms | 25192 KB | Output is correct |
75 | Correct | 183 ms | 25284 KB | Output is correct |
76 | Correct | 186 ms | 24520 KB | Output is correct |
77 | Correct | 184 ms | 24584 KB | Output is correct |
78 | Correct | 185 ms | 25028 KB | Output is correct |
79 | Correct | 310 ms | 38180 KB | Output is correct |