# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
475419 | 2021-09-22T10:14:50 Z | nafis_shifat | Worst Reporter 4 (JOI21_worst_reporter4) | C++14 | 481 ms | 392868 KB |
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> using namespace std; const int mxn=5e3+5; const int inf=1e9; ll c[mxn]; int h[mxn]; vector<int> adj[mxn]; ll dp[mxn][mxn]; ll suf[mxn][mxn]; int n; void dfs(int u) { for(int v : adj[u]) dfs(v); for(int i = 1; i <= n; i++) { dp[u][i] = c[u]; if(i == h[u]) dp[u][i] = 0; for(int v : adj[u]) { dp[u][i] += suf[v][i]; } } suf[u][n] = dp[u][n]; for(int i = n - 1; i >= 1; i--) { suf[u][i] = min(suf[u][i + 1],dp[u][i]); } } int main() { cin >> n; vector<int> v; for(int i = 1; i <= n; i++) { int bap; scanf("%d %d %lld",&bap,&h[i],&c[i]); if(bap != i) adj[bap].push_back(i); v.push_back(h[i]); } sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()), v.end()); for(int i = 1; i <= n; i++) { h[i] = lower_bound(v.begin(),v.end(),h[i]) - v.begin() + 1; } dfs(1); cout<<suf[1][1]<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 265 ms | 392304 KB | Output is correct |
6 | Correct | 239 ms | 392240 KB | Output is correct |
7 | Correct | 240 ms | 392280 KB | Output is correct |
8 | Correct | 236 ms | 392388 KB | Output is correct |
9 | Correct | 255 ms | 392464 KB | Output is correct |
10 | Correct | 238 ms | 392388 KB | Output is correct |
11 | Correct | 236 ms | 392384 KB | Output is correct |
12 | Correct | 232 ms | 392812 KB | Output is correct |
13 | Correct | 237 ms | 392868 KB | Output is correct |
14 | Correct | 237 ms | 392640 KB | Output is correct |
15 | Correct | 266 ms | 392704 KB | Output is correct |
16 | Correct | 234 ms | 392440 KB | Output is correct |
17 | Correct | 232 ms | 392468 KB | Output is correct |
18 | Correct | 245 ms | 392532 KB | Output is correct |
19 | Correct | 234 ms | 392676 KB | Output is correct |
20 | Correct | 236 ms | 392516 KB | Output is correct |
21 | Correct | 244 ms | 392600 KB | Output is correct |
22 | Correct | 481 ms | 392492 KB | Output is correct |
23 | Correct | 480 ms | 392452 KB | Output is correct |
24 | Correct | 342 ms | 392648 KB | Output is correct |
25 | Correct | 348 ms | 392544 KB | Output is correct |
26 | Correct | 242 ms | 392744 KB | Output is correct |
27 | Correct | 236 ms | 392576 KB | Output is correct |
28 | Correct | 243 ms | 392644 KB | Output is correct |
29 | Correct | 234 ms | 392680 KB | Output is correct |
30 | Correct | 238 ms | 392440 KB | Output is correct |
31 | Correct | 256 ms | 392572 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 265 ms | 392304 KB | Output is correct |
6 | Correct | 239 ms | 392240 KB | Output is correct |
7 | Correct | 240 ms | 392280 KB | Output is correct |
8 | Correct | 236 ms | 392388 KB | Output is correct |
9 | Correct | 255 ms | 392464 KB | Output is correct |
10 | Correct | 238 ms | 392388 KB | Output is correct |
11 | Correct | 236 ms | 392384 KB | Output is correct |
12 | Correct | 232 ms | 392812 KB | Output is correct |
13 | Correct | 237 ms | 392868 KB | Output is correct |
14 | Correct | 237 ms | 392640 KB | Output is correct |
15 | Correct | 266 ms | 392704 KB | Output is correct |
16 | Correct | 234 ms | 392440 KB | Output is correct |
17 | Correct | 232 ms | 392468 KB | Output is correct |
18 | Correct | 245 ms | 392532 KB | Output is correct |
19 | Correct | 234 ms | 392676 KB | Output is correct |
20 | Correct | 236 ms | 392516 KB | Output is correct |
21 | Correct | 244 ms | 392600 KB | Output is correct |
22 | Correct | 481 ms | 392492 KB | Output is correct |
23 | Correct | 480 ms | 392452 KB | Output is correct |
24 | Correct | 342 ms | 392648 KB | Output is correct |
25 | Correct | 348 ms | 392544 KB | Output is correct |
26 | Correct | 242 ms | 392744 KB | Output is correct |
27 | Correct | 236 ms | 392576 KB | Output is correct |
28 | Correct | 243 ms | 392644 KB | Output is correct |
29 | Correct | 234 ms | 392680 KB | Output is correct |
30 | Correct | 238 ms | 392440 KB | Output is correct |
31 | Correct | 256 ms | 392572 KB | Output is correct |
32 | Correct | 242 ms | 392516 KB | Output is correct |
33 | Runtime error | 22 ms | 1260 KB | Execution killed with signal 11 |
34 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 265 ms | 392304 KB | Output is correct |
6 | Correct | 239 ms | 392240 KB | Output is correct |
7 | Correct | 240 ms | 392280 KB | Output is correct |
8 | Correct | 236 ms | 392388 KB | Output is correct |
9 | Correct | 255 ms | 392464 KB | Output is correct |
10 | Correct | 238 ms | 392388 KB | Output is correct |
11 | Correct | 236 ms | 392384 KB | Output is correct |
12 | Correct | 232 ms | 392812 KB | Output is correct |
13 | Correct | 237 ms | 392868 KB | Output is correct |
14 | Correct | 237 ms | 392640 KB | Output is correct |
15 | Correct | 266 ms | 392704 KB | Output is correct |
16 | Correct | 234 ms | 392440 KB | Output is correct |
17 | Correct | 232 ms | 392468 KB | Output is correct |
18 | Correct | 245 ms | 392532 KB | Output is correct |
19 | Correct | 234 ms | 392676 KB | Output is correct |
20 | Correct | 236 ms | 392516 KB | Output is correct |
21 | Correct | 244 ms | 392600 KB | Output is correct |
22 | Correct | 481 ms | 392492 KB | Output is correct |
23 | Correct | 480 ms | 392452 KB | Output is correct |
24 | Correct | 342 ms | 392648 KB | Output is correct |
25 | Correct | 348 ms | 392544 KB | Output is correct |
26 | Correct | 242 ms | 392744 KB | Output is correct |
27 | Correct | 236 ms | 392576 KB | Output is correct |
28 | Correct | 243 ms | 392644 KB | Output is correct |
29 | Correct | 234 ms | 392680 KB | Output is correct |
30 | Correct | 238 ms | 392440 KB | Output is correct |
31 | Correct | 256 ms | 392572 KB | Output is correct |
32 | Correct | 242 ms | 392516 KB | Output is correct |
33 | Runtime error | 22 ms | 1260 KB | Execution killed with signal 11 |
34 | Halted | 0 ms | 0 KB | - |