# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
200765 | 2020-02-08T06:09:58 Z | BThero | Fireworks (APIO16_fireworks) | C++17 | 24 ms | 764 KB |
// Why am I so dumb? :c // chrono::system_clock::now().time_since_epoch().count() #include<bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> pii; //template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int MAXN = (int)3e2 + 5; const int INF = (int)1e6; int par[MAXN], arr[MAXN]; vector<int> adj[MAXN]; int dp[MAXN][MAXN]; int n, m; void dfs(int v, int pr = -1) { if (v > n) { for (int i = 1; i <= 300; ++i) { dp[v][i] = INF; } dp[v][0] = 0; return; } for (int to : adj[v]) { if (to == pr) { continue; } dfs(to, v); for (int i = 0; i <= 300; ++i) { int best = INF; for (int j = 0; j <= i; ++j) { best = min(best, dp[to][j] + abs(arr[to] - (i - j))); } dp[v][i] += best; } } } void solve() { scanf("%d %d", &n, &m); for (int i = 2; i <= n + m; ++i) { scanf("%d %d", &par[i], &arr[i]); adj[par[i]].pb(i); } dfs(1); int ans = INF; for (int i = 0; i <= 300; ++i) { ans = min(ans, dp[1][i]); } printf("%d\n", ans); } int main() { int tt = 1; while (tt--) { solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 7 ms | 376 KB | Output is correct |
3 | Correct | 8 ms | 376 KB | Output is correct |
4 | Correct | 10 ms | 504 KB | Output is correct |
5 | Correct | 11 ms | 504 KB | Output is correct |
6 | Correct | 12 ms | 376 KB | Output is correct |
7 | Correct | 14 ms | 504 KB | Output is correct |
8 | Correct | 17 ms | 632 KB | Output is correct |
9 | Correct | 16 ms | 504 KB | Output is correct |
10 | Correct | 18 ms | 632 KB | Output is correct |
11 | Correct | 19 ms | 632 KB | Output is correct |
12 | Correct | 20 ms | 632 KB | Output is correct |
13 | Correct | 20 ms | 632 KB | Output is correct |
14 | Correct | 21 ms | 760 KB | Output is correct |
15 | Correct | 22 ms | 632 KB | Output is correct |
16 | Correct | 24 ms | 764 KB | Output is correct |
17 | Correct | 22 ms | 632 KB | Output is correct |
18 | Correct | 23 ms | 632 KB | Output is correct |
19 | Correct | 22 ms | 632 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |