# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
218212 | 2020-04-01T14:20:52 Z | SamAnd | Fireworks (APIO16_fireworks) | C++17 | 26 ms | 1792 KB |
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 302; const long long INF = 1000000009000000009; int n, m; int p[N]; vector<pair<int, int> > a[N]; long long dp[N][N]; long long dpp[N][N]; void dfs(int x) { if (x > n) { dp[x][0] = 0; return; } for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i].first; dfs(h); for (int j = 0; j < N; ++j) { for (int k = 0; j + k < N; ++k) { dpp[h][j + k] = min(dpp[h][j + k], dp[h][j] + abs(a[x][i].second - k)); } } } for (int j = 0; j < N; ++j) { dp[x][j] = 0; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i].first; dp[x][j] += dpp[h][j]; dp[x][j] = min(dp[x][j], INF); } } } int main() { scanf("%d%d", &n, &m); for (int i = 2; i <= n; ++i) { int d; scanf("%d%d", &p[i], &d); a[p[i]].push_back(m_p(i, d)); } for (int i = n + 1; i <= n + m; ++i) { int d; scanf("%d%d", &p[i], &d); a[p[i]].push_back(m_p(i, d)); } if (n == 1) { long long ans = 0; for (int i = 0; i < a[1].size(); ++i) { long long yans = 0; for (int j = 0; j < a[1].size(); ++j) yans += abs(a[1][i].second - a[1][j].second); ans = min(ans, yans); } printf("%lld\n", ans); return 0; } for (int i = 1; i <= n + m; ++i) { for (int j = 0; j < N; ++j) dpp[i][j] = dp[i][j] = INF; } dfs(1); long long ans = INF; for (int j = 0; j < N; ++j) ans = min(ans, dp[1][j]); printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 7 ms | 512 KB | Output is correct |
3 | Correct | 9 ms | 640 KB | Output is correct |
4 | Correct | 11 ms | 768 KB | Output is correct |
5 | Correct | 13 ms | 896 KB | Output is correct |
6 | Correct | 13 ms | 1024 KB | Output is correct |
7 | Correct | 15 ms | 1024 KB | Output is correct |
8 | Correct | 16 ms | 1152 KB | Output is correct |
9 | Correct | 17 ms | 1280 KB | Output is correct |
10 | Correct | 19 ms | 1408 KB | Output is correct |
11 | Correct | 21 ms | 1664 KB | Output is correct |
12 | Correct | 23 ms | 1536 KB | Output is correct |
13 | Correct | 23 ms | 1664 KB | Output is correct |
14 | Correct | 25 ms | 1792 KB | Output is correct |
15 | Correct | 26 ms | 1792 KB | Output is correct |
16 | Correct | 24 ms | 1792 KB | Output is correct |
17 | Correct | 25 ms | 1792 KB | Output is correct |
18 | Correct | 25 ms | 1792 KB | Output is correct |
19 | Correct | 25 ms | 1792 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |