답안 #434054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
434054 2021-06-20T14:31:24 Z amoo_safar Worst Reporter 4 (JOI21_worst_reporter4) C++17
79 / 100
408 ms 524292 KB
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

map<int, ll> mp[N];

int a[N], h[N], c[N];
vector<int> G[N];

void DFS(int u){
	for(auto adj : G[u]){
		if(adj == u) continue;
		DFS(adj);
		if(mp[adj].size() > mp[u].size())
			mp[u].swap(mp[adj]);
		for(auto [la, sm] : mp[adj])
			mp[u][la] += sm;
	}
	ll del = c[u];
	while(del){
		auto it = mp[u].lower_bound(h[u] + 1);
		if(it == mp[u].end())
			break;
		ll rm = min(del, it -> S);
		del -= rm;
		if(rm < it -> S){
			mp[u][it -> F] -= rm;
		} else mp[u].erase(it);
	}
	mp[u][h[u]] += c[u];

	// cerr << "!! " << u << " : \n";
	// for(auto [x, y] : mp[u])
	// 	cerr << x << ' ' << y << '\n';
	// cerr << "------\n";
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> h[i] >> c[i];
		G[a[i]].pb(i);
		h[i] = -h[i];
	}
	DFS(1);
	
	ll ans = 0;
	for(int i = 1; i <= n; i++) ans += c[i];
	for(auto [la, sm] : mp[1]) ans -= sm;
	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14372 KB Output is correct
3 Correct 10 ms 14300 KB Output is correct
4 Correct 11 ms 14412 KB Output is correct
5 Correct 16 ms 15532 KB Output is correct
6 Correct 14 ms 15180 KB Output is correct
7 Correct 14 ms 15000 KB Output is correct
8 Correct 20 ms 15692 KB Output is correct
9 Correct 14 ms 15180 KB Output is correct
10 Correct 13 ms 14920 KB Output is correct
11 Correct 12 ms 14752 KB Output is correct
12 Correct 14 ms 15388 KB Output is correct
13 Correct 13 ms 15436 KB Output is correct
14 Correct 13 ms 15052 KB Output is correct
15 Correct 13 ms 15052 KB Output is correct
16 Correct 16 ms 15984 KB Output is correct
17 Correct 14 ms 15308 KB Output is correct
18 Correct 12 ms 14808 KB Output is correct
19 Correct 14 ms 15312 KB Output is correct
20 Correct 13 ms 15184 KB Output is correct
21 Correct 12 ms 15180 KB Output is correct
22 Correct 13 ms 15172 KB Output is correct
23 Correct 12 ms 14924 KB Output is correct
24 Correct 14 ms 15308 KB Output is correct
25 Correct 12 ms 15180 KB Output is correct
26 Correct 13 ms 15436 KB Output is correct
27 Correct 14 ms 15308 KB Output is correct
28 Correct 14 ms 15436 KB Output is correct
29 Correct 18 ms 15620 KB Output is correct
30 Correct 14 ms 15448 KB Output is correct
31 Correct 15 ms 15564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14372 KB Output is correct
3 Correct 10 ms 14300 KB Output is correct
4 Correct 11 ms 14412 KB Output is correct
5 Correct 16 ms 15532 KB Output is correct
6 Correct 14 ms 15180 KB Output is correct
7 Correct 14 ms 15000 KB Output is correct
8 Correct 20 ms 15692 KB Output is correct
9 Correct 14 ms 15180 KB Output is correct
10 Correct 13 ms 14920 KB Output is correct
11 Correct 12 ms 14752 KB Output is correct
12 Correct 14 ms 15388 KB Output is correct
13 Correct 13 ms 15436 KB Output is correct
14 Correct 13 ms 15052 KB Output is correct
15 Correct 13 ms 15052 KB Output is correct
16 Correct 16 ms 15984 KB Output is correct
17 Correct 14 ms 15308 KB Output is correct
18 Correct 12 ms 14808 KB Output is correct
19 Correct 14 ms 15312 KB Output is correct
20 Correct 13 ms 15184 KB Output is correct
21 Correct 12 ms 15180 KB Output is correct
22 Correct 13 ms 15172 KB Output is correct
23 Correct 12 ms 14924 KB Output is correct
24 Correct 14 ms 15308 KB Output is correct
25 Correct 12 ms 15180 KB Output is correct
26 Correct 13 ms 15436 KB Output is correct
27 Correct 14 ms 15308 KB Output is correct
28 Correct 14 ms 15436 KB Output is correct
29 Correct 18 ms 15620 KB Output is correct
30 Correct 14 ms 15448 KB Output is correct
31 Correct 15 ms 15564 KB Output is correct
32 Correct 16 ms 15564 KB Output is correct
33 Correct 408 ms 79444 KB Output is correct
34 Correct 331 ms 54472 KB Output is correct
35 Correct 372 ms 76388 KB Output is correct
36 Correct 291 ms 54596 KB Output is correct
37 Correct 194 ms 35532 KB Output is correct
38 Correct 219 ms 31044 KB Output is correct
39 Correct 193 ms 56364 KB Output is correct
40 Correct 189 ms 56360 KB Output is correct
41 Correct 128 ms 56292 KB Output is correct
42 Correct 186 ms 42328 KB Output is correct
43 Correct 192 ms 42208 KB Output is correct
44 Correct 394 ms 104312 KB Output is correct
45 Correct 304 ms 68720 KB Output is correct
46 Correct 116 ms 31168 KB Output is correct
47 Correct 400 ms 52160 KB Output is correct
48 Correct 152 ms 45232 KB Output is correct
49 Correct 122 ms 45288 KB Output is correct
50 Correct 337 ms 46780 KB Output is correct
51 Correct 129 ms 34272 KB Output is correct
52 Correct 341 ms 52800 KB Output is correct
53 Correct 148 ms 45796 KB Output is correct
54 Correct 146 ms 56532 KB Output is correct
55 Correct 242 ms 53776 KB Output is correct
56 Correct 222 ms 59588 KB Output is correct
57 Correct 215 ms 62592 KB Output is correct
58 Correct 237 ms 60288 KB Output is correct
59 Correct 225 ms 60188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14372 KB Output is correct
3 Correct 10 ms 14300 KB Output is correct
4 Correct 11 ms 14412 KB Output is correct
5 Correct 16 ms 15532 KB Output is correct
6 Correct 14 ms 15180 KB Output is correct
7 Correct 14 ms 15000 KB Output is correct
8 Correct 20 ms 15692 KB Output is correct
9 Correct 14 ms 15180 KB Output is correct
10 Correct 13 ms 14920 KB Output is correct
11 Correct 12 ms 14752 KB Output is correct
12 Correct 14 ms 15388 KB Output is correct
13 Correct 13 ms 15436 KB Output is correct
14 Correct 13 ms 15052 KB Output is correct
15 Correct 13 ms 15052 KB Output is correct
16 Correct 16 ms 15984 KB Output is correct
17 Correct 14 ms 15308 KB Output is correct
18 Correct 12 ms 14808 KB Output is correct
19 Correct 14 ms 15312 KB Output is correct
20 Correct 13 ms 15184 KB Output is correct
21 Correct 12 ms 15180 KB Output is correct
22 Correct 13 ms 15172 KB Output is correct
23 Correct 12 ms 14924 KB Output is correct
24 Correct 14 ms 15308 KB Output is correct
25 Correct 12 ms 15180 KB Output is correct
26 Correct 13 ms 15436 KB Output is correct
27 Correct 14 ms 15308 KB Output is correct
28 Correct 14 ms 15436 KB Output is correct
29 Correct 18 ms 15620 KB Output is correct
30 Correct 14 ms 15448 KB Output is correct
31 Correct 15 ms 15564 KB Output is correct
32 Correct 16 ms 15564 KB Output is correct
33 Correct 408 ms 79444 KB Output is correct
34 Correct 331 ms 54472 KB Output is correct
35 Correct 372 ms 76388 KB Output is correct
36 Correct 291 ms 54596 KB Output is correct
37 Correct 194 ms 35532 KB Output is correct
38 Correct 219 ms 31044 KB Output is correct
39 Correct 193 ms 56364 KB Output is correct
40 Correct 189 ms 56360 KB Output is correct
41 Correct 128 ms 56292 KB Output is correct
42 Correct 186 ms 42328 KB Output is correct
43 Correct 192 ms 42208 KB Output is correct
44 Correct 394 ms 104312 KB Output is correct
45 Correct 304 ms 68720 KB Output is correct
46 Correct 116 ms 31168 KB Output is correct
47 Correct 400 ms 52160 KB Output is correct
48 Correct 152 ms 45232 KB Output is correct
49 Correct 122 ms 45288 KB Output is correct
50 Correct 337 ms 46780 KB Output is correct
51 Correct 129 ms 34272 KB Output is correct
52 Correct 341 ms 52800 KB Output is correct
53 Correct 148 ms 45796 KB Output is correct
54 Correct 146 ms 56532 KB Output is correct
55 Correct 242 ms 53776 KB Output is correct
56 Correct 222 ms 59588 KB Output is correct
57 Correct 215 ms 62592 KB Output is correct
58 Correct 237 ms 60288 KB Output is correct
59 Correct 225 ms 60188 KB Output is correct
60 Runtime error 369 ms 524292 KB Execution killed with signal 9
61 Halted 0 ms 0 KB -