# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
414960 | 2021-05-31T11:15:06 Z | 송준혁(#7511) | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 391 ms | 106220 KB |
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define lb lower_bound #define MOD 1000000007 #define INF (1ll<<62) using namespace std; typedef long long LL; typedef pair<LL,LL> pii; int N; LL ans, C[202020]; int P[202020], A[202020], B[202020]; vector<int> adj[202020]; map<LL,LL> D[202020]; void dfs(int u){ for (int v : adj[u]){ dfs(v); if (D[u].size() < D[v].size()) swap(D[u], D[v]), swap(C[u], C[v]); for (pii t : D[v]) D[u][t.fi] += t.se; C[u] += C[v]; } D[u][A[u]+1] += B[u], C[u] += B[u]; auto it = D[u].lower_bound(A[u]+1); int dy = B[u]; while (it != D[u].begin()){ --it; if (it->se > dy){ D[u][it->fi] -= dy; dy = 0; break; } else{ int x = it->fi; dy -= it->se; D[u].erase(x); it = D[u].lower_bound(x); } } C[u] -= dy; } int main(){ scanf("%d", &N); for (int i=1; i<=N; i++){ scanf("%d %d %d", &P[i], &A[i], &B[i]); if (P[i] != i) adj[P[i]].pb(i); } for (int i=1; i<=N; i++) if (P[i] == i) dfs(i), ans += C[i]; printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 14540 KB | Output is correct |
2 | Correct | 11 ms | 14504 KB | Output is correct |
3 | Correct | 10 ms | 14540 KB | Output is correct |
4 | Correct | 12 ms | 14468 KB | Output is correct |
5 | Correct | 18 ms | 15736 KB | Output is correct |
6 | Correct | 15 ms | 15364 KB | Output is correct |
7 | Correct | 13 ms | 15052 KB | Output is correct |
8 | Correct | 17 ms | 15784 KB | Output is correct |
9 | Correct | 23 ms | 15308 KB | Output is correct |
10 | Correct | 15 ms | 15060 KB | Output is correct |
11 | Correct | 13 ms | 14976 KB | Output is correct |
12 | Correct | 14 ms | 15692 KB | Output is correct |
13 | Correct | 13 ms | 15636 KB | Output is correct |
14 | Correct | 14 ms | 15252 KB | Output is correct |
15 | Correct | 13 ms | 15308 KB | Output is correct |
16 | Correct | 16 ms | 16072 KB | Output is correct |
17 | Correct | 15 ms | 15564 KB | Output is correct |
18 | Correct | 15 ms | 14916 KB | Output is correct |
19 | Correct | 15 ms | 15436 KB | Output is correct |
20 | Correct | 13 ms | 15312 KB | Output is correct |
21 | Correct | 13 ms | 15308 KB | Output is correct |
22 | Correct | 14 ms | 15332 KB | Output is correct |
23 | Correct | 13 ms | 15052 KB | Output is correct |
24 | Correct | 17 ms | 15564 KB | Output is correct |
25 | Correct | 13 ms | 15308 KB | Output is correct |
26 | Correct | 13 ms | 15692 KB | Output is correct |
27 | Correct | 16 ms | 15432 KB | Output is correct |
28 | Correct | 15 ms | 15536 KB | Output is correct |
29 | Correct | 14 ms | 15704 KB | Output is correct |
30 | Correct | 14 ms | 15692 KB | Output is correct |
31 | Correct | 15 ms | 15692 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 14540 KB | Output is correct |
2 | Correct | 11 ms | 14504 KB | Output is correct |
3 | Correct | 10 ms | 14540 KB | Output is correct |
4 | Correct | 12 ms | 14468 KB | Output is correct |
5 | Correct | 18 ms | 15736 KB | Output is correct |
6 | Correct | 15 ms | 15364 KB | Output is correct |
7 | Correct | 13 ms | 15052 KB | Output is correct |
8 | Correct | 17 ms | 15784 KB | Output is correct |
9 | Correct | 23 ms | 15308 KB | Output is correct |
10 | Correct | 15 ms | 15060 KB | Output is correct |
11 | Correct | 13 ms | 14976 KB | Output is correct |
12 | Correct | 14 ms | 15692 KB | Output is correct |
13 | Correct | 13 ms | 15636 KB | Output is correct |
14 | Correct | 14 ms | 15252 KB | Output is correct |
15 | Correct | 13 ms | 15308 KB | Output is correct |
16 | Correct | 16 ms | 16072 KB | Output is correct |
17 | Correct | 15 ms | 15564 KB | Output is correct |
18 | Correct | 15 ms | 14916 KB | Output is correct |
19 | Correct | 15 ms | 15436 KB | Output is correct |
20 | Correct | 13 ms | 15312 KB | Output is correct |
21 | Correct | 13 ms | 15308 KB | Output is correct |
22 | Correct | 14 ms | 15332 KB | Output is correct |
23 | Correct | 13 ms | 15052 KB | Output is correct |
24 | Correct | 17 ms | 15564 KB | Output is correct |
25 | Correct | 13 ms | 15308 KB | Output is correct |
26 | Correct | 13 ms | 15692 KB | Output is correct |
27 | Correct | 16 ms | 15432 KB | Output is correct |
28 | Correct | 15 ms | 15536 KB | Output is correct |
29 | Correct | 14 ms | 15704 KB | Output is correct |
30 | Correct | 14 ms | 15692 KB | Output is correct |
31 | Correct | 15 ms | 15692 KB | Output is correct |
32 | Correct | 16 ms | 15820 KB | Output is correct |
33 | Correct | 391 ms | 81020 KB | Output is correct |
34 | Correct | 326 ms | 56168 KB | Output is correct |
35 | Correct | 381 ms | 78108 KB | Output is correct |
36 | Correct | 298 ms | 56292 KB | Output is correct |
37 | Correct | 217 ms | 37232 KB | Output is correct |
38 | Correct | 190 ms | 32708 KB | Output is correct |
39 | Correct | 226 ms | 61324 KB | Output is correct |
40 | Correct | 193 ms | 61056 KB | Output is correct |
41 | Correct | 129 ms | 61060 KB | Output is correct |
42 | Correct | 228 ms | 45576 KB | Output is correct |
43 | Correct | 205 ms | 45568 KB | Output is correct |
44 | Correct | 360 ms | 106220 KB | Output is correct |
45 | Correct | 260 ms | 70340 KB | Output is correct |
46 | Correct | 118 ms | 32752 KB | Output is correct |
47 | Correct | 286 ms | 55452 KB | Output is correct |
48 | Correct | 151 ms | 48468 KB | Output is correct |
49 | Correct | 122 ms | 48420 KB | Output is correct |
50 | Correct | 247 ms | 48476 KB | Output is correct |
51 | Correct | 124 ms | 36024 KB | Output is correct |
52 | Correct | 323 ms | 56096 KB | Output is correct |
53 | Correct | 144 ms | 49072 KB | Output is correct |
54 | Correct | 152 ms | 61324 KB | Output is correct |
55 | Correct | 257 ms | 57040 KB | Output is correct |
56 | Correct | 207 ms | 63820 KB | Output is correct |
57 | Correct | 196 ms | 67096 KB | Output is correct |
58 | Correct | 257 ms | 63536 KB | Output is correct |
59 | Correct | 251 ms | 63460 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 14540 KB | Output is correct |
2 | Correct | 11 ms | 14504 KB | Output is correct |
3 | Correct | 10 ms | 14540 KB | Output is correct |
4 | Correct | 12 ms | 14468 KB | Output is correct |
5 | Correct | 18 ms | 15736 KB | Output is correct |
6 | Correct | 15 ms | 15364 KB | Output is correct |
7 | Correct | 13 ms | 15052 KB | Output is correct |
8 | Correct | 17 ms | 15784 KB | Output is correct |
9 | Correct | 23 ms | 15308 KB | Output is correct |
10 | Correct | 15 ms | 15060 KB | Output is correct |
11 | Correct | 13 ms | 14976 KB | Output is correct |
12 | Correct | 14 ms | 15692 KB | Output is correct |
13 | Correct | 13 ms | 15636 KB | Output is correct |
14 | Correct | 14 ms | 15252 KB | Output is correct |
15 | Correct | 13 ms | 15308 KB | Output is correct |
16 | Correct | 16 ms | 16072 KB | Output is correct |
17 | Correct | 15 ms | 15564 KB | Output is correct |
18 | Correct | 15 ms | 14916 KB | Output is correct |
19 | Correct | 15 ms | 15436 KB | Output is correct |
20 | Correct | 13 ms | 15312 KB | Output is correct |
21 | Correct | 13 ms | 15308 KB | Output is correct |
22 | Correct | 14 ms | 15332 KB | Output is correct |
23 | Correct | 13 ms | 15052 KB | Output is correct |
24 | Correct | 17 ms | 15564 KB | Output is correct |
25 | Correct | 13 ms | 15308 KB | Output is correct |
26 | Correct | 13 ms | 15692 KB | Output is correct |
27 | Correct | 16 ms | 15432 KB | Output is correct |
28 | Correct | 15 ms | 15536 KB | Output is correct |
29 | Correct | 14 ms | 15704 KB | Output is correct |
30 | Correct | 14 ms | 15692 KB | Output is correct |
31 | Correct | 15 ms | 15692 KB | Output is correct |
32 | Correct | 16 ms | 15820 KB | Output is correct |
33 | Correct | 391 ms | 81020 KB | Output is correct |
34 | Correct | 326 ms | 56168 KB | Output is correct |
35 | Correct | 381 ms | 78108 KB | Output is correct |
36 | Correct | 298 ms | 56292 KB | Output is correct |
37 | Correct | 217 ms | 37232 KB | Output is correct |
38 | Correct | 190 ms | 32708 KB | Output is correct |
39 | Correct | 226 ms | 61324 KB | Output is correct |
40 | Correct | 193 ms | 61056 KB | Output is correct |
41 | Correct | 129 ms | 61060 KB | Output is correct |
42 | Correct | 228 ms | 45576 KB | Output is correct |
43 | Correct | 205 ms | 45568 KB | Output is correct |
44 | Correct | 360 ms | 106220 KB | Output is correct |
45 | Correct | 260 ms | 70340 KB | Output is correct |
46 | Correct | 118 ms | 32752 KB | Output is correct |
47 | Correct | 286 ms | 55452 KB | Output is correct |
48 | Correct | 151 ms | 48468 KB | Output is correct |
49 | Correct | 122 ms | 48420 KB | Output is correct |
50 | Correct | 247 ms | 48476 KB | Output is correct |
51 | Correct | 124 ms | 36024 KB | Output is correct |
52 | Correct | 323 ms | 56096 KB | Output is correct |
53 | Correct | 144 ms | 49072 KB | Output is correct |
54 | Correct | 152 ms | 61324 KB | Output is correct |
55 | Correct | 257 ms | 57040 KB | Output is correct |
56 | Correct | 207 ms | 63820 KB | Output is correct |
57 | Correct | 196 ms | 67096 KB | Output is correct |
58 | Correct | 257 ms | 63536 KB | Output is correct |
59 | Correct | 251 ms | 63460 KB | Output is correct |
60 | Incorrect | 10 ms | 14536 KB | Output isn't correct |
61 | Halted | 0 ms | 0 KB | - |