# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
389774 | 2021-04-14T14:04:00 Z | georgerapeanu | Worst Reporter 4 (JOI21_worst_reporter4) | C++11 | 926 ms | 524292 KB |
#include <bits/stdc++.h> using namespace std; struct slope_magic_t{ map<int,long long> slope_change; void merge(slope_magic_t &other){ for(auto it:other.slope_change){ slope_change[it.first] += it.second; } } void add_value(int value,int cost){ slope_change[0] += cost; slope_change[value] -= cost; slope_change[value + 1] += cost; long long relative_height = 0; map<int,long long> :: iterator it,it2; it = slope_change.lower_bound(value); long long current_diff = slope_change[value]; while(current_diff < 0){ it2 = it; if(it2 == slope_change.begin()){ break; } it2--; if(it2 == slope_change.begin() || current_diff + it2->second > 0){ it2->second += current_diff; slope_change.erase(it); break; } relative_height = -current_diff - it2->second; slope_change.erase(it2); current_diff = -relative_height; } } int size(){ return (int)slope_change.size(); } void swap(slope_magic_t &other){ slope_change.swap(other.slope_change); } }; const int NMAX = 2e5; int n; slope_magic_t dp[NMAX + 5]; vector<int> graph[NMAX + 5]; int father[NMAX + 5]; int c[NMAX + 5]; int h[NMAX + 5]; void dfs(int nod,int lvl){ for(auto it:graph[nod]){ dfs(it,lvl + 1); if(dp[it].size() > dp[nod].size()){ dp[nod].swap(dp[it]); } dp[nod].merge(dp[it]); } dp[nod].add_value(h[nod],c[nod]); } int main(){ scanf("%d",&n); for(int i = 1;i <= n;i++){ scanf("%d %d %d",&father[i],&h[i],&c[i]); if(father[i] == i){ continue; } graph[father[i]].push_back(i); } dfs(1,0); printf("%lld\n",dp[1].slope_change[0]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 14284 KB | Output is correct |
2 | Correct | 8 ms | 14408 KB | Output is correct |
3 | Correct | 8 ms | 14284 KB | Output is correct |
4 | Correct | 8 ms | 14284 KB | Output is correct |
5 | Correct | 16 ms | 15676 KB | Output is correct |
6 | Correct | 13 ms | 15308 KB | Output is correct |
7 | Correct | 13 ms | 15052 KB | Output is correct |
8 | Correct | 15 ms | 15812 KB | Output is correct |
9 | Correct | 14 ms | 15300 KB | Output is correct |
10 | Correct | 13 ms | 15052 KB | Output is correct |
11 | Correct | 12 ms | 14980 KB | Output is correct |
12 | Correct | 13 ms | 15436 KB | Output is correct |
13 | Correct | 13 ms | 15360 KB | Output is correct |
14 | Correct | 13 ms | 15012 KB | Output is correct |
15 | Correct | 12 ms | 15052 KB | Output is correct |
16 | Correct | 15 ms | 16076 KB | Output is correct |
17 | Correct | 14 ms | 15436 KB | Output is correct |
18 | Correct | 34 ms | 14880 KB | Output is correct |
19 | Correct | 13 ms | 15436 KB | Output is correct |
20 | Correct | 12 ms | 15236 KB | Output is correct |
21 | Correct | 12 ms | 15308 KB | Output is correct |
22 | Correct | 13 ms | 15440 KB | Output is correct |
23 | Correct | 12 ms | 15160 KB | Output is correct |
24 | Correct | 13 ms | 15428 KB | Output is correct |
25 | Correct | 12 ms | 15308 KB | Output is correct |
26 | Correct | 16 ms | 15684 KB | Output is correct |
27 | Correct | 14 ms | 15536 KB | Output is correct |
28 | Correct | 13 ms | 15556 KB | Output is correct |
29 | Correct | 13 ms | 15564 KB | Output is correct |
30 | Correct | 14 ms | 15540 KB | Output is correct |
31 | Correct | 13 ms | 15436 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 15692 KB | Output is correct |
2 | Correct | 418 ms | 82812 KB | Output is correct |
3 | Correct | 334 ms | 57772 KB | Output is correct |
4 | Correct | 425 ms | 79808 KB | Output is correct |
5 | Correct | 331 ms | 57908 KB | Output is correct |
6 | Correct | 267 ms | 38932 KB | Output is correct |
7 | Correct | 219 ms | 34512 KB | Output is correct |
8 | Correct | 204 ms | 53260 KB | Output is correct |
9 | Correct | 194 ms | 53188 KB | Output is correct |
10 | Correct | 140 ms | 53224 KB | Output is correct |
11 | Correct | 220 ms | 39344 KB | Output is correct |
12 | Correct | 187 ms | 39236 KB | Output is correct |
13 | Correct | 409 ms | 107736 KB | Output is correct |
14 | Correct | 301 ms | 72124 KB | Output is correct |
15 | Correct | 137 ms | 34480 KB | Output is correct |
16 | Correct | 326 ms | 55560 KB | Output is correct |
17 | Correct | 199 ms | 48704 KB | Output is correct |
18 | Correct | 134 ms | 48452 KB | Output is correct |
19 | Correct | 294 ms | 57188 KB | Output is correct |
20 | Correct | 153 ms | 44724 KB | Output is correct |
21 | Correct | 384 ms | 56064 KB | Output is correct |
22 | Correct | 167 ms | 49088 KB | Output is correct |
23 | Correct | 312 ms | 65764 KB | Output is correct |
24 | Correct | 298 ms | 57964 KB | Output is correct |
25 | Correct | 238 ms | 60740 KB | Output is correct |
26 | Correct | 231 ms | 62532 KB | Output is correct |
27 | Correct | 262 ms | 57924 KB | Output is correct |
28 | Correct | 259 ms | 57880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 14284 KB | Output is correct |
2 | Correct | 8 ms | 14408 KB | Output is correct |
3 | Correct | 8 ms | 14284 KB | Output is correct |
4 | Correct | 8 ms | 14284 KB | Output is correct |
5 | Correct | 16 ms | 15676 KB | Output is correct |
6 | Correct | 13 ms | 15308 KB | Output is correct |
7 | Correct | 13 ms | 15052 KB | Output is correct |
8 | Correct | 15 ms | 15812 KB | Output is correct |
9 | Correct | 14 ms | 15300 KB | Output is correct |
10 | Correct | 13 ms | 15052 KB | Output is correct |
11 | Correct | 12 ms | 14980 KB | Output is correct |
12 | Correct | 13 ms | 15436 KB | Output is correct |
13 | Correct | 13 ms | 15360 KB | Output is correct |
14 | Correct | 13 ms | 15012 KB | Output is correct |
15 | Correct | 12 ms | 15052 KB | Output is correct |
16 | Correct | 15 ms | 16076 KB | Output is correct |
17 | Correct | 14 ms | 15436 KB | Output is correct |
18 | Correct | 34 ms | 14880 KB | Output is correct |
19 | Correct | 13 ms | 15436 KB | Output is correct |
20 | Correct | 12 ms | 15236 KB | Output is correct |
21 | Correct | 12 ms | 15308 KB | Output is correct |
22 | Correct | 13 ms | 15440 KB | Output is correct |
23 | Correct | 12 ms | 15160 KB | Output is correct |
24 | Correct | 13 ms | 15428 KB | Output is correct |
25 | Correct | 12 ms | 15308 KB | Output is correct |
26 | Correct | 16 ms | 15684 KB | Output is correct |
27 | Correct | 14 ms | 15536 KB | Output is correct |
28 | Correct | 13 ms | 15556 KB | Output is correct |
29 | Correct | 13 ms | 15564 KB | Output is correct |
30 | Correct | 14 ms | 15540 KB | Output is correct |
31 | Correct | 13 ms | 15436 KB | Output is correct |
32 | Correct | 15 ms | 15692 KB | Output is correct |
33 | Correct | 418 ms | 82812 KB | Output is correct |
34 | Correct | 334 ms | 57772 KB | Output is correct |
35 | Correct | 425 ms | 79808 KB | Output is correct |
36 | Correct | 331 ms | 57908 KB | Output is correct |
37 | Correct | 267 ms | 38932 KB | Output is correct |
38 | Correct | 219 ms | 34512 KB | Output is correct |
39 | Correct | 204 ms | 53260 KB | Output is correct |
40 | Correct | 194 ms | 53188 KB | Output is correct |
41 | Correct | 140 ms | 53224 KB | Output is correct |
42 | Correct | 220 ms | 39344 KB | Output is correct |
43 | Correct | 187 ms | 39236 KB | Output is correct |
44 | Correct | 409 ms | 107736 KB | Output is correct |
45 | Correct | 301 ms | 72124 KB | Output is correct |
46 | Correct | 137 ms | 34480 KB | Output is correct |
47 | Correct | 326 ms | 55560 KB | Output is correct |
48 | Correct | 199 ms | 48704 KB | Output is correct |
49 | Correct | 134 ms | 48452 KB | Output is correct |
50 | Correct | 294 ms | 57188 KB | Output is correct |
51 | Correct | 153 ms | 44724 KB | Output is correct |
52 | Correct | 384 ms | 56064 KB | Output is correct |
53 | Correct | 167 ms | 49088 KB | Output is correct |
54 | Correct | 312 ms | 65764 KB | Output is correct |
55 | Correct | 298 ms | 57964 KB | Output is correct |
56 | Correct | 238 ms | 60740 KB | Output is correct |
57 | Correct | 231 ms | 62532 KB | Output is correct |
58 | Correct | 262 ms | 57924 KB | Output is correct |
59 | Correct | 259 ms | 57880 KB | Output is correct |
60 | Runtime error | 926 ms | 524292 KB | Execution killed with signal 9 |
61 | Halted | 0 ms | 0 KB | - |