# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153794 | 2019-09-16T10:54:43 Z | arnold518 | Fireworks (APIO16_fireworks) | C++14 | 28 ms | 7928 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 3e5; int N, M; vector<pii> adj[MAXN+10]; int dp[MAXN+10][400], ans=987654321; void dfs(int now) { int i, j; if(now>N) { dp[now][0]=0; for(i=1; i<=300; i++) dp[now][i]=987654321; return; } for(auto nxt : adj[now]) dfs(nxt.first); for(i=0; i<=300; i++) { dp[now][i]=0; for(auto nxt : adj[now]) { int t=987654321; for(j=0; j<=i; j++) t=min(t, dp[nxt.first][j]+abs(i-j-nxt.second)); dp[now][i]+=t; } } } int main() { int i, j; scanf("%d%d", &N, &M); for(i=2; i<=N+M; i++) { int p, c; scanf("%d%d", &p, &c); adj[p].push_back({i, c}); } dfs(1); ans=987654321; for(i=0; i<=300; i++) ans=min(ans, dp[1][i]); printf("%d", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 7416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 11 ms | 7416 KB | Output is correct |
3 | Correct | 12 ms | 7416 KB | Output is correct |
4 | Correct | 14 ms | 7544 KB | Output is correct |
5 | Correct | 16 ms | 7548 KB | Output is correct |
6 | Correct | 17 ms | 7544 KB | Output is correct |
7 | Correct | 19 ms | 7544 KB | Output is correct |
8 | Correct | 20 ms | 7800 KB | Output is correct |
9 | Correct | 21 ms | 7672 KB | Output is correct |
10 | Correct | 22 ms | 7672 KB | Output is correct |
11 | Correct | 24 ms | 7800 KB | Output is correct |
12 | Correct | 25 ms | 7800 KB | Output is correct |
13 | Correct | 26 ms | 7928 KB | Output is correct |
14 | Correct | 28 ms | 7928 KB | Output is correct |
15 | Correct | 28 ms | 7928 KB | Output is correct |
16 | Correct | 28 ms | 7800 KB | Output is correct |
17 | Correct | 28 ms | 7928 KB | Output is correct |
18 | Correct | 28 ms | 7800 KB | Output is correct |
19 | Correct | 28 ms | 7928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 7416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 7416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |