# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
470391 | 2021-09-03T16:15:28 Z | fefe | Fireworks (APIO16_fireworks) | C++17 | 6 ms | 7372 KB |
#include<bits/stdc++.h> #define pb push_back #define fi first #define se second #define all(v) (v).begin(), (v).end() using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pil; const int MAXN = 300005; int n, m; int par[MAXN]; LL val[MAXN]; pil mid[MAXN]; vector<LL> lst[MAXN]; void udt(int i) { lst[par[i]].pb(mid[i].fi + val[i]); lst[par[i]].pb(mid[i].se + val[i]); } int main() { scanf("%d %d", &n, &m); for (int i = 2; i <= n + m; i++) { int p; LL v; scanf("%d %lld", &p, &v); par[i] = p; val[i] = v; } for (int i = n + m; i > n; i--) { mid[i] = pil(0, 0); udt(i); } for (int i = n; i >= 1; i--) { sort(all(lst[i])); mid[i].fi = lst[i][lst[i].size() / 2 - 1]; mid[i].se = lst[i][lst[i].size() / 2]; udt(i); } val[1] = mid[1].se; LL res = 0; for (int i = 2; i <= n + m; i++) { LL v = val[par[i]] - val[i]; if (abs(mid[i].fi - v) < abs(mid[i].se - v)) { val[i] = mid[i].fi; res += abs(mid[i].fi - v); } else { val[i] = mid[i].se; res += abs(mid[i].se - v); } } printf("%lld\n", res); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7244 KB | Output is correct |
2 | Correct | 5 ms | 7244 KB | Output is correct |
3 | Correct | 5 ms | 7288 KB | Output is correct |
4 | Correct | 6 ms | 7372 KB | Output is correct |
5 | Correct | 5 ms | 7348 KB | Output is correct |
6 | Correct | 5 ms | 7372 KB | Output is correct |
7 | Correct | 5 ms | 7372 KB | Output is correct |
8 | Correct | 5 ms | 7352 KB | Output is correct |
9 | Correct | 5 ms | 7372 KB | Output is correct |
10 | Correct | 5 ms | 7352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 7244 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7244 KB | Output is correct |
2 | Correct | 5 ms | 7244 KB | Output is correct |
3 | Correct | 5 ms | 7288 KB | Output is correct |
4 | Correct | 6 ms | 7372 KB | Output is correct |
5 | Correct | 5 ms | 7348 KB | Output is correct |
6 | Correct | 5 ms | 7372 KB | Output is correct |
7 | Correct | 5 ms | 7372 KB | Output is correct |
8 | Correct | 5 ms | 7352 KB | Output is correct |
9 | Correct | 5 ms | 7372 KB | Output is correct |
10 | Correct | 5 ms | 7352 KB | Output is correct |
11 | Incorrect | 4 ms | 7244 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7244 KB | Output is correct |
2 | Correct | 5 ms | 7244 KB | Output is correct |
3 | Correct | 5 ms | 7288 KB | Output is correct |
4 | Correct | 6 ms | 7372 KB | Output is correct |
5 | Correct | 5 ms | 7348 KB | Output is correct |
6 | Correct | 5 ms | 7372 KB | Output is correct |
7 | Correct | 5 ms | 7372 KB | Output is correct |
8 | Correct | 5 ms | 7352 KB | Output is correct |
9 | Correct | 5 ms | 7372 KB | Output is correct |
10 | Correct | 5 ms | 7352 KB | Output is correct |
11 | Incorrect | 4 ms | 7244 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |