# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
792880 | 2023-07-25T10:16:33 Z | IvanJ | Fireworks (APIO16_fireworks) | C++17 | 24 ms | 1108 KB |
#include<bits/stdc++.h> #define pb push_back #define x first #define y second #define all(a) (a).begin(), (a).end() using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 305; int n, m; int dp[maxn][maxn]; vector<ii> adj[maxn]; int rek(int x, int len) { if(dp[x][len] != -1) return dp[x][len]; if(adj[x].size() == 0) return dp[x][len] = (len == 0) ? 0 : 1e9; int ret = 0; for(auto p : adj[x]) { int reti = 1e9; for(int i = 0;i <= len;i++) { int l = len - i; reti = min(reti, rek(p.x, i) + abs(p.y - l)); } ret += reti; } return dp[x][len] = ret; } int main() { scanf("%d%d", &n, &m); for(int i = 1;i < n + m;i++) { int p, c; scanf("%d%d", &p, &c); p--; adj[p].pb({i, c}); } if(n == 1) { vector<int> v; for(auto p : adj[0]) v.pb(p.y); sort(all(v)); int med = v[m / 2]; ll ans = 0; for(int i : v) ans += (ll)abs(i - med); printf("%lld\n", ans); return 0; } memset(dp, -1, sizeof dp); int ans = 1e9; for(int i = 0;i < maxn;i++) ans = min(ans, rek(0, i)); printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 320 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 320 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 596 KB | Output is correct |
2 | Correct | 5 ms | 672 KB | Output is correct |
3 | Correct | 7 ms | 676 KB | Output is correct |
4 | Correct | 7 ms | 596 KB | Output is correct |
5 | Correct | 9 ms | 596 KB | Output is correct |
6 | Correct | 11 ms | 676 KB | Output is correct |
7 | Correct | 12 ms | 596 KB | Output is correct |
8 | Correct | 14 ms | 680 KB | Output is correct |
9 | Correct | 15 ms | 676 KB | Output is correct |
10 | Correct | 17 ms | 596 KB | Output is correct |
11 | Correct | 19 ms | 596 KB | Output is correct |
12 | Correct | 20 ms | 596 KB | Output is correct |
13 | Correct | 24 ms | 596 KB | Output is correct |
14 | Correct | 23 ms | 700 KB | Output is correct |
15 | Correct | 24 ms | 668 KB | Output is correct |
16 | Correct | 24 ms | 596 KB | Output is correct |
17 | Correct | 24 ms | 676 KB | Output is correct |
18 | Correct | 23 ms | 596 KB | Output is correct |
19 | Correct | 23 ms | 596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 320 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 320 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 596 KB | Output is correct |
12 | Correct | 5 ms | 672 KB | Output is correct |
13 | Correct | 7 ms | 676 KB | Output is correct |
14 | Correct | 7 ms | 596 KB | Output is correct |
15 | Correct | 9 ms | 596 KB | Output is correct |
16 | Correct | 11 ms | 676 KB | Output is correct |
17 | Correct | 12 ms | 596 KB | Output is correct |
18 | Correct | 14 ms | 680 KB | Output is correct |
19 | Correct | 15 ms | 676 KB | Output is correct |
20 | Correct | 17 ms | 596 KB | Output is correct |
21 | Correct | 19 ms | 596 KB | Output is correct |
22 | Correct | 20 ms | 596 KB | Output is correct |
23 | Correct | 24 ms | 596 KB | Output is correct |
24 | Correct | 23 ms | 700 KB | Output is correct |
25 | Correct | 24 ms | 668 KB | Output is correct |
26 | Correct | 24 ms | 596 KB | Output is correct |
27 | Correct | 24 ms | 676 KB | Output is correct |
28 | Correct | 23 ms | 596 KB | Output is correct |
29 | Correct | 23 ms | 596 KB | Output is correct |
30 | Runtime error | 1 ms | 1108 KB | Execution killed with signal 11 |
31 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 320 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 320 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 596 KB | Output is correct |
12 | Correct | 5 ms | 672 KB | Output is correct |
13 | Correct | 7 ms | 676 KB | Output is correct |
14 | Correct | 7 ms | 596 KB | Output is correct |
15 | Correct | 9 ms | 596 KB | Output is correct |
16 | Correct | 11 ms | 676 KB | Output is correct |
17 | Correct | 12 ms | 596 KB | Output is correct |
18 | Correct | 14 ms | 680 KB | Output is correct |
19 | Correct | 15 ms | 676 KB | Output is correct |
20 | Correct | 17 ms | 596 KB | Output is correct |
21 | Correct | 19 ms | 596 KB | Output is correct |
22 | Correct | 20 ms | 596 KB | Output is correct |
23 | Correct | 24 ms | 596 KB | Output is correct |
24 | Correct | 23 ms | 700 KB | Output is correct |
25 | Correct | 24 ms | 668 KB | Output is correct |
26 | Correct | 24 ms | 596 KB | Output is correct |
27 | Correct | 24 ms | 676 KB | Output is correct |
28 | Correct | 23 ms | 596 KB | Output is correct |
29 | Correct | 23 ms | 596 KB | Output is correct |
30 | Runtime error | 1 ms | 1108 KB | Execution killed with signal 11 |
31 | Halted | 0 ms | 0 KB | - |