답안 #542096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542096 2022-03-25T10:56:30 Z someone Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
2000 ms 208884 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e5 + 42, INF = 1e18 + 42;

bool vu[N];
vector<int> adj[N];
int n, h[N], cost[N];

multiset<pair<int, int>> DFS(int i, int pre) {
    vu[i] = true;
    multiset<pair<int, int>> ans;
    ans.insert({0, cost[i]});
    ans.insert({h[i]+1, cost[i]});
    
    for(int j : adj[i])
        if(j != pre) {
            multiset<pair<int, int>> fils = DFS(j, i);
            if(ans.size() < fils.size())
                swap(ans, fils);
            for(auto p : fils)
                ans.insert(p);
        }
    
    int suppr = cost[i];
    while(suppr) {
        auto it = ans.lower_bound({h[i]+1, 0});
        it--;
        if((*it).second <= suppr) {
            suppr -= (*it).second;
            ans.erase(it);
        } else {
            auto copy = (*it);
            ans.erase(it);
            ans.insert({copy.first, copy.second - suppr});
            suppr = 0;
        }
    }
    
    return ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a >> h[i] >> cost[i];
        if(i != a-1)
            adj[a-1].push_back(i);
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++)
        if(!vu[i]) {
            multiset<pair<int, int>> slope = DFS(i, i);
            for(auto p : slope)
                if(p.first == 0)
                    ans += p.second;
                else
                    break;
        }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 8 ms 5588 KB Output is correct
6 Correct 8 ms 5460 KB Output is correct
7 Correct 8 ms 5460 KB Output is correct
8 Correct 9 ms 5524 KB Output is correct
9 Correct 8 ms 5588 KB Output is correct
10 Correct 8 ms 5588 KB Output is correct
11 Correct 10 ms 5460 KB Output is correct
12 Correct 10 ms 6960 KB Output is correct
13 Correct 9 ms 6892 KB Output is correct
14 Correct 9 ms 6256 KB Output is correct
15 Correct 9 ms 6356 KB Output is correct
16 Correct 10 ms 5716 KB Output is correct
17 Correct 9 ms 5716 KB Output is correct
18 Correct 9 ms 5672 KB Output is correct
19 Correct 8 ms 6100 KB Output is correct
20 Correct 8 ms 6100 KB Output is correct
21 Correct 8 ms 6192 KB Output is correct
22 Correct 6 ms 5484 KB Output is correct
23 Correct 6 ms 5588 KB Output is correct
24 Correct 7 ms 6192 KB Output is correct
25 Correct 7 ms 6192 KB Output is correct
26 Correct 8 ms 6968 KB Output is correct
27 Correct 7 ms 5940 KB Output is correct
28 Correct 7 ms 6228 KB Output is correct
29 Correct 8 ms 6608 KB Output is correct
30 Correct 8 ms 6740 KB Output is correct
31 Correct 8 ms 6740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 8 ms 5588 KB Output is correct
6 Correct 8 ms 5460 KB Output is correct
7 Correct 8 ms 5460 KB Output is correct
8 Correct 9 ms 5524 KB Output is correct
9 Correct 8 ms 5588 KB Output is correct
10 Correct 8 ms 5588 KB Output is correct
11 Correct 10 ms 5460 KB Output is correct
12 Correct 10 ms 6960 KB Output is correct
13 Correct 9 ms 6892 KB Output is correct
14 Correct 9 ms 6256 KB Output is correct
15 Correct 9 ms 6356 KB Output is correct
16 Correct 10 ms 5716 KB Output is correct
17 Correct 9 ms 5716 KB Output is correct
18 Correct 9 ms 5672 KB Output is correct
19 Correct 8 ms 6100 KB Output is correct
20 Correct 8 ms 6100 KB Output is correct
21 Correct 8 ms 6192 KB Output is correct
22 Correct 6 ms 5484 KB Output is correct
23 Correct 6 ms 5588 KB Output is correct
24 Correct 7 ms 6192 KB Output is correct
25 Correct 7 ms 6192 KB Output is correct
26 Correct 8 ms 6968 KB Output is correct
27 Correct 7 ms 5940 KB Output is correct
28 Correct 7 ms 6228 KB Output is correct
29 Correct 8 ms 6608 KB Output is correct
30 Correct 8 ms 6740 KB Output is correct
31 Correct 8 ms 6740 KB Output is correct
32 Correct 8 ms 5588 KB Output is correct
33 Correct 365 ms 35232 KB Output is correct
34 Correct 354 ms 33528 KB Output is correct
35 Correct 359 ms 32200 KB Output is correct
36 Correct 352 ms 33932 KB Output is correct
37 Correct 368 ms 35832 KB Output is correct
38 Correct 314 ms 29544 KB Output is correct
39 Correct 353 ms 82360 KB Output is correct
40 Correct 371 ms 82340 KB Output is correct
41 Correct 369 ms 82396 KB Output is correct
42 Correct 376 ms 57420 KB Output is correct
43 Correct 374 ms 57616 KB Output is correct
44 Correct 363 ms 35496 KB Output is correct
45 Correct 366 ms 35508 KB Output is correct
46 Correct 320 ms 33356 KB Output is correct
47 Correct 314 ms 48516 KB Output is correct
48 Correct 349 ms 52380 KB Output is correct
49 Correct 301 ms 52792 KB Output is correct
50 Correct 200 ms 26640 KB Output is correct
51 Correct 161 ms 26692 KB Output is correct
52 Correct 319 ms 54924 KB Output is correct
53 Correct 340 ms 54952 KB Output is correct
54 Correct 234 ms 82560 KB Output is correct
55 Correct 256 ms 50720 KB Output is correct
56 Correct 310 ms 64860 KB Output is correct
57 Correct 295 ms 71140 KB Output is correct
58 Correct 332 ms 75356 KB Output is correct
59 Correct 330 ms 75380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 8 ms 5588 KB Output is correct
6 Correct 8 ms 5460 KB Output is correct
7 Correct 8 ms 5460 KB Output is correct
8 Correct 9 ms 5524 KB Output is correct
9 Correct 8 ms 5588 KB Output is correct
10 Correct 8 ms 5588 KB Output is correct
11 Correct 10 ms 5460 KB Output is correct
12 Correct 10 ms 6960 KB Output is correct
13 Correct 9 ms 6892 KB Output is correct
14 Correct 9 ms 6256 KB Output is correct
15 Correct 9 ms 6356 KB Output is correct
16 Correct 10 ms 5716 KB Output is correct
17 Correct 9 ms 5716 KB Output is correct
18 Correct 9 ms 5672 KB Output is correct
19 Correct 8 ms 6100 KB Output is correct
20 Correct 8 ms 6100 KB Output is correct
21 Correct 8 ms 6192 KB Output is correct
22 Correct 6 ms 5484 KB Output is correct
23 Correct 6 ms 5588 KB Output is correct
24 Correct 7 ms 6192 KB Output is correct
25 Correct 7 ms 6192 KB Output is correct
26 Correct 8 ms 6968 KB Output is correct
27 Correct 7 ms 5940 KB Output is correct
28 Correct 7 ms 6228 KB Output is correct
29 Correct 8 ms 6608 KB Output is correct
30 Correct 8 ms 6740 KB Output is correct
31 Correct 8 ms 6740 KB Output is correct
32 Correct 8 ms 5588 KB Output is correct
33 Correct 365 ms 35232 KB Output is correct
34 Correct 354 ms 33528 KB Output is correct
35 Correct 359 ms 32200 KB Output is correct
36 Correct 352 ms 33932 KB Output is correct
37 Correct 368 ms 35832 KB Output is correct
38 Correct 314 ms 29544 KB Output is correct
39 Correct 353 ms 82360 KB Output is correct
40 Correct 371 ms 82340 KB Output is correct
41 Correct 369 ms 82396 KB Output is correct
42 Correct 376 ms 57420 KB Output is correct
43 Correct 374 ms 57616 KB Output is correct
44 Correct 363 ms 35496 KB Output is correct
45 Correct 366 ms 35508 KB Output is correct
46 Correct 320 ms 33356 KB Output is correct
47 Correct 314 ms 48516 KB Output is correct
48 Correct 349 ms 52380 KB Output is correct
49 Correct 301 ms 52792 KB Output is correct
50 Correct 200 ms 26640 KB Output is correct
51 Correct 161 ms 26692 KB Output is correct
52 Correct 319 ms 54924 KB Output is correct
53 Correct 340 ms 54952 KB Output is correct
54 Correct 234 ms 82560 KB Output is correct
55 Correct 256 ms 50720 KB Output is correct
56 Correct 310 ms 64860 KB Output is correct
57 Correct 295 ms 71140 KB Output is correct
58 Correct 332 ms 75356 KB Output is correct
59 Correct 330 ms 75380 KB Output is correct
60 Correct 3 ms 5028 KB Output is correct
61 Correct 3 ms 4948 KB Output is correct
62 Correct 3 ms 5032 KB Output is correct
63 Correct 3 ms 5028 KB Output is correct
64 Execution timed out 2097 ms 208884 KB Time limit exceeded
65 Halted 0 ms 0 KB -