# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45146 | 2018-04-11T14:20:21 Z | erdemkiraz | Fireworks (APIO16_fireworks) | C++11 | 352 ms | 1640 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair < int, int > ii; const int N = 600 + 5; int n, m; vector < ii > v[N]; int dp[N][N], dp2[N]; void dfs(int x) { for(auto u : v[x]) dfs(u.first); if(x > n) { for(int i = 1; i < N; i++) dp[x][i] = 1e9; return; } for(auto u : v[x]) { for(int i = 0; i < N; i++) dp2[i] = 1e9; for(int i = 0; i < N; i++) for(int j = -N; j < N; j++) if(u.second + j >= 0 and i + j + u.second < N) dp2[i + j + u.second] = min(dp2[i + j + u.second], dp[u.first][i] + abs(j)); for(int i = 0; i < N; i++) dp[x][i] += dp2[i]; } } int main() { scanf("%d %d", &n, &m); for(int i = 2; i <= n + m; i++) { int x, c; scanf("%d %d", &x, &c); v[x].push_back({i, c}); } dfs(1); int res = 1e9; for(int i = 0; i <= 600; i++) { res = min(res, dp[1][i]); } printf("%d\n", res); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 376 KB | Output is correct |
2 | Correct | 34 ms | 668 KB | Output is correct |
3 | Correct | 54 ms | 668 KB | Output is correct |
4 | Correct | 93 ms | 744 KB | Output is correct |
5 | Correct | 108 ms | 852 KB | Output is correct |
6 | Correct | 121 ms | 964 KB | Output is correct |
7 | Correct | 145 ms | 988 KB | Output is correct |
8 | Correct | 163 ms | 1016 KB | Output is correct |
9 | Correct | 176 ms | 1016 KB | Output is correct |
10 | Correct | 195 ms | 1276 KB | Output is correct |
11 | Correct | 220 ms | 1276 KB | Output is correct |
12 | Correct | 245 ms | 1472 KB | Output is correct |
13 | Correct | 280 ms | 1472 KB | Output is correct |
14 | Correct | 278 ms | 1472 KB | Output is correct |
15 | Correct | 331 ms | 1472 KB | Output is correct |
16 | Correct | 352 ms | 1484 KB | Output is correct |
17 | Correct | 280 ms | 1532 KB | Output is correct |
18 | Correct | 287 ms | 1640 KB | Output is correct |
19 | Correct | 276 ms | 1640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |