답안 #725917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725917 2023-04-18T08:49:48 Z MohammadAghil Worst Reporter 4 (JOI21_worst_reporter4) C++17
79 / 100
339 ms 106776 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define all(x) begin(x), end(x)
#define sz(x) (int)size(x)
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> pp;

void dbg(){
     cerr << endl;
}
template<typename H, typename... T> void dbg(H h, T... t){
     cerr << h << ", ";
     dbg(t...);
}

void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     #ifndef ONLINE_JUDGE
          // freopen("inp.txt", "r", stdin);
          // freopen("out.txt", "w", stdout);
          #define er(...) cerr << __LINE__ << " <" << #__VA_ARGS__ << ">: ", dbg(__VA_ARGS__)
     #else
          #define er(...) 0
     #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1e9 + 7, mod2 = 1e9 + 9, maxn = 2e5 + 5, lg = 21, inf = ll(1e9) + 5;

ll pw(ll a, ll b){
     if(b == 0) return 1;
     ll k = pw(a, b>>1);
     return k*k*(b&1ll?a:1);  
}

vector<int> adj[maxn];
ll par[maxn], H[maxn], C[maxn], nxt[maxn];

map<ll, ll> mp[maxn];

void dfs(int r){
     for(int c: adj[r]){
          dfs(c);
          if(sz(mp[c]) > sz(mp[r])) mp[r].swap(mp[c]);
          for(auto&x: mp[c]) mp[r][x.ff] += x.ss;
     }
     mp[r][H[r]] += C[r];
     ll cr = C[r];
     while(cr){
          auto it = mp[r].upper_bound(H[r]);
          if(it == end(mp[r])) return;
          ll mn = min(cr, it->ss);
          cr -= mn, it->ss -= mn;
          if(it->ss == 0) mp[r].erase(it->ff);
     }
}

int main(){ IOS();  
     int n; cin >> n;
     ll sum = 0;
     rep(i,0,n){
          cin >> nxt[i] >> H[i] >> C[i];
          nxt[i]--;
          H[i] = -H[i];
          sum += C[i];
          if(i) adj[nxt[i]].pb(i);
     }
     dfs(0);
     for(auto&c: mp[0]) sum -= c.ss;
     cout << sum << '\n';
     return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14424 KB Output is correct
5 Correct 13 ms 15720 KB Output is correct
6 Correct 12 ms 15336 KB Output is correct
7 Correct 10 ms 14952 KB Output is correct
8 Correct 13 ms 15768 KB Output is correct
9 Correct 11 ms 15188 KB Output is correct
10 Correct 11 ms 15060 KB Output is correct
11 Correct 11 ms 14952 KB Output is correct
12 Correct 11 ms 15332 KB Output is correct
13 Correct 10 ms 15360 KB Output is correct
14 Correct 11 ms 15084 KB Output is correct
15 Correct 11 ms 15060 KB Output is correct
16 Correct 15 ms 15976 KB Output is correct
17 Correct 12 ms 15444 KB Output is correct
18 Correct 10 ms 14828 KB Output is correct
19 Correct 13 ms 15444 KB Output is correct
20 Correct 13 ms 15076 KB Output is correct
21 Correct 13 ms 15080 KB Output is correct
22 Correct 11 ms 15316 KB Output is correct
23 Correct 10 ms 14952 KB Output is correct
24 Correct 11 ms 15336 KB Output is correct
25 Correct 10 ms 15188 KB Output is correct
26 Correct 11 ms 15316 KB Output is correct
27 Correct 12 ms 15316 KB Output is correct
28 Correct 11 ms 15468 KB Output is correct
29 Correct 11 ms 15464 KB Output is correct
30 Correct 15 ms 15444 KB Output is correct
31 Correct 12 ms 15480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14424 KB Output is correct
5 Correct 13 ms 15720 KB Output is correct
6 Correct 12 ms 15336 KB Output is correct
7 Correct 10 ms 14952 KB Output is correct
8 Correct 13 ms 15768 KB Output is correct
9 Correct 11 ms 15188 KB Output is correct
10 Correct 11 ms 15060 KB Output is correct
11 Correct 11 ms 14952 KB Output is correct
12 Correct 11 ms 15332 KB Output is correct
13 Correct 10 ms 15360 KB Output is correct
14 Correct 11 ms 15084 KB Output is correct
15 Correct 11 ms 15060 KB Output is correct
16 Correct 15 ms 15976 KB Output is correct
17 Correct 12 ms 15444 KB Output is correct
18 Correct 10 ms 14828 KB Output is correct
19 Correct 13 ms 15444 KB Output is correct
20 Correct 13 ms 15076 KB Output is correct
21 Correct 13 ms 15080 KB Output is correct
22 Correct 11 ms 15316 KB Output is correct
23 Correct 10 ms 14952 KB Output is correct
24 Correct 11 ms 15336 KB Output is correct
25 Correct 10 ms 15188 KB Output is correct
26 Correct 11 ms 15316 KB Output is correct
27 Correct 12 ms 15316 KB Output is correct
28 Correct 11 ms 15468 KB Output is correct
29 Correct 11 ms 15464 KB Output is correct
30 Correct 15 ms 15444 KB Output is correct
31 Correct 12 ms 15480 KB Output is correct
32 Correct 13 ms 15700 KB Output is correct
33 Correct 339 ms 81796 KB Output is correct
34 Correct 266 ms 56912 KB Output is correct
35 Correct 316 ms 78772 KB Output is correct
36 Correct 260 ms 56952 KB Output is correct
37 Correct 186 ms 37956 KB Output is correct
38 Correct 155 ms 33376 KB Output is correct
39 Correct 165 ms 52560 KB Output is correct
40 Correct 164 ms 52324 KB Output is correct
41 Correct 104 ms 52360 KB Output is correct
42 Correct 164 ms 41612 KB Output is correct
43 Correct 159 ms 41496 KB Output is correct
44 Correct 305 ms 106776 KB Output is correct
45 Correct 225 ms 71128 KB Output is correct
46 Correct 103 ms 33440 KB Output is correct
47 Correct 270 ms 51456 KB Output is correct
48 Correct 141 ms 44412 KB Output is correct
49 Correct 94 ms 44456 KB Output is correct
50 Correct 234 ms 49180 KB Output is correct
51 Correct 88 ms 36640 KB Output is correct
52 Correct 284 ms 52092 KB Output is correct
53 Correct 107 ms 45016 KB Output is correct
54 Correct 103 ms 52620 KB Output is correct
55 Correct 186 ms 53004 KB Output is correct
56 Correct 165 ms 57360 KB Output is correct
57 Correct 155 ms 59724 KB Output is correct
58 Correct 183 ms 59588 KB Output is correct
59 Correct 170 ms 59428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 8 ms 14424 KB Output is correct
5 Correct 13 ms 15720 KB Output is correct
6 Correct 12 ms 15336 KB Output is correct
7 Correct 10 ms 14952 KB Output is correct
8 Correct 13 ms 15768 KB Output is correct
9 Correct 11 ms 15188 KB Output is correct
10 Correct 11 ms 15060 KB Output is correct
11 Correct 11 ms 14952 KB Output is correct
12 Correct 11 ms 15332 KB Output is correct
13 Correct 10 ms 15360 KB Output is correct
14 Correct 11 ms 15084 KB Output is correct
15 Correct 11 ms 15060 KB Output is correct
16 Correct 15 ms 15976 KB Output is correct
17 Correct 12 ms 15444 KB Output is correct
18 Correct 10 ms 14828 KB Output is correct
19 Correct 13 ms 15444 KB Output is correct
20 Correct 13 ms 15076 KB Output is correct
21 Correct 13 ms 15080 KB Output is correct
22 Correct 11 ms 15316 KB Output is correct
23 Correct 10 ms 14952 KB Output is correct
24 Correct 11 ms 15336 KB Output is correct
25 Correct 10 ms 15188 KB Output is correct
26 Correct 11 ms 15316 KB Output is correct
27 Correct 12 ms 15316 KB Output is correct
28 Correct 11 ms 15468 KB Output is correct
29 Correct 11 ms 15464 KB Output is correct
30 Correct 15 ms 15444 KB Output is correct
31 Correct 12 ms 15480 KB Output is correct
32 Correct 13 ms 15700 KB Output is correct
33 Correct 339 ms 81796 KB Output is correct
34 Correct 266 ms 56912 KB Output is correct
35 Correct 316 ms 78772 KB Output is correct
36 Correct 260 ms 56952 KB Output is correct
37 Correct 186 ms 37956 KB Output is correct
38 Correct 155 ms 33376 KB Output is correct
39 Correct 165 ms 52560 KB Output is correct
40 Correct 164 ms 52324 KB Output is correct
41 Correct 104 ms 52360 KB Output is correct
42 Correct 164 ms 41612 KB Output is correct
43 Correct 159 ms 41496 KB Output is correct
44 Correct 305 ms 106776 KB Output is correct
45 Correct 225 ms 71128 KB Output is correct
46 Correct 103 ms 33440 KB Output is correct
47 Correct 270 ms 51456 KB Output is correct
48 Correct 141 ms 44412 KB Output is correct
49 Correct 94 ms 44456 KB Output is correct
50 Correct 234 ms 49180 KB Output is correct
51 Correct 88 ms 36640 KB Output is correct
52 Correct 284 ms 52092 KB Output is correct
53 Correct 107 ms 45016 KB Output is correct
54 Correct 103 ms 52620 KB Output is correct
55 Correct 186 ms 53004 KB Output is correct
56 Correct 165 ms 57360 KB Output is correct
57 Correct 155 ms 59724 KB Output is correct
58 Correct 183 ms 59588 KB Output is correct
59 Correct 170 ms 59428 KB Output is correct
60 Correct 7 ms 14428 KB Output is correct
61 Incorrect 8 ms 14428 KB Output isn't correct
62 Halted 0 ms 0 KB -