# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242295 | 2020-06-27T08:25:38 Z | cheeheng | Magic Tree (CEOI19_magictree) | C++14 | 381 ms | 55544 KB |
#include <bits/stdc++.h> using namespace std; vector<int> AdjList[100005]; int d[100005]; long long w[100005]; int L[100005]; long long subtreeSum[100005][25]; // subtree rooted at i, day x void dfs1(int i, int x){ long long ans = (d[i] == x)*w[i]; for(int j: AdjList[i]){ dfs1(j, x); ans += subtreeSum[j][x]; } subtreeSum[i][x] = ans; } long long memo[100005][25]; long long dfs2(int i, int k){ if(k == 0){ return 0; }else if(memo[i][k] != -1){ return memo[i][k]; } long long ans = 0; // delaying for 1 more day is acceptable //ans = dfs2(i, k-1); long long temp2 = 0; for(int j: AdjList[i]){ // either choose to cut or do not cut long long tempVal = dfs2(j, k); if(d[j] <= k){ tempVal = max(tempVal, w[j] + dfs2(j, d[j])); } temp2 += tempVal; } ans = max(ans, temp2); return memo[i][k] = ans; } int main(){ int n, m, k; scanf("%d%d%d", &n, &m, &k); bool subtask3 = true; for(int i = 2; i <= n; i ++){ int p; scanf("%d", &p); subtask3 &= (p == i-1); AdjList[p].push_back(i); } bool subtask2 = true; long long ans2 = 0; memset(d, -1, sizeof(d)); for(int i = 1; i <= m; i ++){ int x, y, z; scanf("%d%d%d", &x, &y, &z); subtask3 &= (z == 1); subtask2 &= AdjList[x].empty(); d[x] = y; w[x] = z; ans2 += w[x]; } if(subtask2){ printf("%lld", ans2); return 0; } if(subtask3){ int lis = 0; /*for(int i = n; i >= 2; i --){ printf("%d ", d[i]); } printf("\n");*/ for(int i = n; i >= 2; i --){ if(d[i] == -1){continue;} int pos = upper_bound(L, L+lis, d[i])-L; L[pos] = d[i]; if(pos == lis){ lis ++; } } printf("%d\n", lis); return 0; }else if(k <= 20){ for(int i = 0; i <= k; i ++){ dfs1(1, i); } memset(memo, -1, sizeof(memo)); printf("%lld\n", dfs2(1, k)); return 0; }else{ throw; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 22656 KB | Output is correct |
2 | Correct | 17 ms | 22656 KB | Output is correct |
3 | Correct | 16 ms | 22656 KB | Output is correct |
4 | Correct | 16 ms | 22656 KB | Output is correct |
5 | Correct | 7 ms | 3072 KB | Output is correct |
6 | Correct | 6 ms | 3072 KB | Output is correct |
7 | Correct | 7 ms | 3072 KB | Output is correct |
8 | Correct | 16 ms | 22656 KB | Output is correct |
9 | Correct | 17 ms | 22596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 5268 KB | Output is correct |
2 | Correct | 37 ms | 5656 KB | Output is correct |
3 | Correct | 75 ms | 4544 KB | Output is correct |
4 | Correct | 72 ms | 4344 KB | Output is correct |
5 | Correct | 62 ms | 4600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 3200 KB | Output is correct |
2 | Correct | 7 ms | 3072 KB | Output is correct |
3 | Correct | 7 ms | 3072 KB | Output is correct |
4 | Correct | 56 ms | 7032 KB | Output is correct |
5 | Correct | 61 ms | 7416 KB | Output is correct |
6 | Correct | 64 ms | 7032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 148 ms | 44792 KB | Output is correct |
2 | Correct | 137 ms | 44528 KB | Output is correct |
3 | Correct | 147 ms | 49272 KB | Output is correct |
4 | Correct | 88 ms | 43500 KB | Output is correct |
5 | Correct | 107 ms | 55544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 22656 KB | Output is correct |
2 | Correct | 17 ms | 22656 KB | Output is correct |
3 | Correct | 16 ms | 22656 KB | Output is correct |
4 | Correct | 16 ms | 22656 KB | Output is correct |
5 | Correct | 7 ms | 3072 KB | Output is correct |
6 | Correct | 6 ms | 3072 KB | Output is correct |
7 | Correct | 7 ms | 3072 KB | Output is correct |
8 | Correct | 16 ms | 22656 KB | Output is correct |
9 | Correct | 17 ms | 22596 KB | Output is correct |
10 | Correct | 381 ms | 44668 KB | Output is correct |
11 | Correct | 274 ms | 44664 KB | Output is correct |
12 | Correct | 321 ms | 49188 KB | Output is correct |
13 | Correct | 109 ms | 43504 KB | Output is correct |
14 | Correct | 57 ms | 7160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 17 ms | 7040 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 22656 KB | Output is correct |
2 | Correct | 17 ms | 22656 KB | Output is correct |
3 | Correct | 16 ms | 22656 KB | Output is correct |
4 | Correct | 16 ms | 22656 KB | Output is correct |
5 | Correct | 7 ms | 3072 KB | Output is correct |
6 | Correct | 6 ms | 3072 KB | Output is correct |
7 | Correct | 7 ms | 3072 KB | Output is correct |
8 | Correct | 16 ms | 22656 KB | Output is correct |
9 | Correct | 17 ms | 22596 KB | Output is correct |
10 | Correct | 8 ms | 3200 KB | Output is correct |
11 | Correct | 7 ms | 3072 KB | Output is correct |
12 | Correct | 7 ms | 3072 KB | Output is correct |
13 | Correct | 56 ms | 7032 KB | Output is correct |
14 | Correct | 61 ms | 7416 KB | Output is correct |
15 | Correct | 64 ms | 7032 KB | Output is correct |
16 | Correct | 381 ms | 44668 KB | Output is correct |
17 | Correct | 274 ms | 44664 KB | Output is correct |
18 | Correct | 321 ms | 49188 KB | Output is correct |
19 | Correct | 109 ms | 43504 KB | Output is correct |
20 | Correct | 57 ms | 7160 KB | Output is correct |
21 | Runtime error | 23 ms | 7296 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 22656 KB | Output is correct |
2 | Correct | 17 ms | 22656 KB | Output is correct |
3 | Correct | 16 ms | 22656 KB | Output is correct |
4 | Correct | 16 ms | 22656 KB | Output is correct |
5 | Correct | 7 ms | 3072 KB | Output is correct |
6 | Correct | 6 ms | 3072 KB | Output is correct |
7 | Correct | 7 ms | 3072 KB | Output is correct |
8 | Correct | 16 ms | 22656 KB | Output is correct |
9 | Correct | 17 ms | 22596 KB | Output is correct |
10 | Correct | 50 ms | 5268 KB | Output is correct |
11 | Correct | 37 ms | 5656 KB | Output is correct |
12 | Correct | 75 ms | 4544 KB | Output is correct |
13 | Correct | 72 ms | 4344 KB | Output is correct |
14 | Correct | 62 ms | 4600 KB | Output is correct |
15 | Correct | 8 ms | 3200 KB | Output is correct |
16 | Correct | 7 ms | 3072 KB | Output is correct |
17 | Correct | 7 ms | 3072 KB | Output is correct |
18 | Correct | 56 ms | 7032 KB | Output is correct |
19 | Correct | 61 ms | 7416 KB | Output is correct |
20 | Correct | 64 ms | 7032 KB | Output is correct |
21 | Correct | 148 ms | 44792 KB | Output is correct |
22 | Correct | 137 ms | 44528 KB | Output is correct |
23 | Correct | 147 ms | 49272 KB | Output is correct |
24 | Correct | 88 ms | 43500 KB | Output is correct |
25 | Correct | 107 ms | 55544 KB | Output is correct |
26 | Correct | 381 ms | 44668 KB | Output is correct |
27 | Correct | 274 ms | 44664 KB | Output is correct |
28 | Correct | 321 ms | 49188 KB | Output is correct |
29 | Correct | 109 ms | 43504 KB | Output is correct |
30 | Correct | 57 ms | 7160 KB | Output is correct |
31 | Runtime error | 17 ms | 7040 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
32 | Halted | 0 ms | 0 KB | - |