# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334673 | 2020-12-09T18:15:08 Z | iulia13 | 바이오칩 (IZhO12_biochips) | C++14 | 1321 ms | 524292 KB |
#include <iostream> #include <deque> #include <vector> using namespace std; int dp[505][400005]; vector <int> g[200005]; int v[200005]; int in[200005]; int out[200005]; int ord[400005]; int timp = 0; void dfs(int nod) { timp++; ord[timp] = nod; for (int i = 0; i < g[nod].size(); i++) { int x = g[nod][i]; dfs(x); } out[nod] = ++timp; } int main() { int n, m, i, j, r, k, l, x; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> x >> v[i]; if (x) g[x].push_back(i); else r = i; } dfs(r); for (j = 0; j <= m; j++) for (i = 1; i <= timp; i++) dp[j][i] = -2e9; dp[0][1] = 0; for (j = 0; j <= m; j++) for (i = 1; i <= timp; i++) { int last = out[ord[i]]; dp[j][i + 1] = max(dp[j][i + 1], dp[j][i]); if (j < m) dp[j + 1][last] = max(dp[j + 1][last], dp[j][i] + v[ord[i]]); } cout << dp[m][timp]; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 5100 KB | Output is correct |
2 | Correct | 4 ms | 5120 KB | Output is correct |
3 | Correct | 4 ms | 5228 KB | Output is correct |
4 | Correct | 21 ms | 10092 KB | Output is correct |
5 | Correct | 26 ms | 11884 KB | Output is correct |
6 | Correct | 31 ms | 13932 KB | Output is correct |
7 | Correct | 1314 ms | 359020 KB | Output is correct |
8 | Correct | 1321 ms | 359024 KB | Output is correct |
9 | Runtime error | 388 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
10 | Halted | 0 ms | 0 KB | - |