답안 #540398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540398 2022-03-20T09:52:27 Z cheissmart Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
306 ms 51940 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string to_string(pi p) {
	return "(" + to_string(p.F) + ", " + to_string(p.S) + ")";
}

template<class T> string to_string(T t) {
	string s = "[";
	bool f = false;
	for(auto&e:t) {
		if(f) s += ", ";
		s += to_string(e);
		f = true;
	}
	s += "]";
	return s;
}

void dbg() { cerr << "]" << endl; }
template<class H, class...T> void dbg(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t)) cerr << ", ";
	dbg(t...);
}

#define debug(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", dbg(__VA_ARGS__)

const int INF = 1e9 + 7, N = 2e5 + 7;

int p[N], h[N], c[N];
vi G[N];

multiset<pi> dfs(int u) {
	multiset<pi> s;
	for(int v:G[u]) {
		auto t = dfs(v);
		if(SZ(s) < SZ(t)) swap(s, t);
		for(auto& e:t) s.insert(e);
	}
	s.insert({h[u], c[u]});
	auto it = s.lower_bound({h[u] + 1, -INF});
	int res = -c[u], lst = -1;
	while(it != s.end() && res < 0) {
		res += it -> S;
		lst = it -> F;
		it = s.erase(it);
	}
	if(res > 0 && lst != -1)
		s.insert({lst, res});
	return s;
}

signed main()
{
	IO_OP;

	int n;
	cin >> n;
	ll tot = 0;
	for(int i = 1; i <= n; i++) {
		cin >> p[i] >> h[i] >> c[i];
		h[i] = 1e9 + 1 - h[i];
		tot += c[i];
		if(i != 1) G[p[i]].PB(i);
	}
	auto s = dfs(1);
	ll ans = 0;
	for(auto[x, y]:s)
		ans += y;
	cout << tot - ans << '\n';	
	
}

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:83:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   83 |  for(auto[x, y]:s)
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5088 KB Output is correct
2 Correct 3 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 7 ms 5460 KB Output is correct
6 Correct 7 ms 5428 KB Output is correct
7 Correct 7 ms 5460 KB Output is correct
8 Correct 7 ms 5420 KB Output is correct
9 Correct 8 ms 5404 KB Output is correct
10 Correct 7 ms 5420 KB Output is correct
11 Correct 8 ms 5460 KB Output is correct
12 Correct 7 ms 6060 KB Output is correct
13 Correct 6 ms 6100 KB Output is correct
14 Correct 7 ms 5776 KB Output is correct
15 Correct 7 ms 5716 KB Output is correct
16 Correct 8 ms 5480 KB Output is correct
17 Correct 8 ms 5460 KB Output is correct
18 Correct 11 ms 5588 KB Output is correct
19 Correct 8 ms 5716 KB Output is correct
20 Correct 7 ms 5716 KB Output is correct
21 Correct 7 ms 5676 KB Output is correct
22 Correct 5 ms 5424 KB Output is correct
23 Correct 5 ms 5460 KB Output is correct
24 Correct 7 ms 5800 KB Output is correct
25 Correct 6 ms 5808 KB Output is correct
26 Correct 5 ms 6060 KB Output is correct
27 Correct 5 ms 5720 KB Output is correct
28 Correct 6 ms 5844 KB Output is correct
29 Correct 8 ms 6060 KB Output is correct
30 Correct 6 ms 5972 KB Output is correct
31 Correct 7 ms 6100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5088 KB Output is correct
2 Correct 3 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 7 ms 5460 KB Output is correct
6 Correct 7 ms 5428 KB Output is correct
7 Correct 7 ms 5460 KB Output is correct
8 Correct 7 ms 5420 KB Output is correct
9 Correct 8 ms 5404 KB Output is correct
10 Correct 7 ms 5420 KB Output is correct
11 Correct 8 ms 5460 KB Output is correct
12 Correct 7 ms 6060 KB Output is correct
13 Correct 6 ms 6100 KB Output is correct
14 Correct 7 ms 5776 KB Output is correct
15 Correct 7 ms 5716 KB Output is correct
16 Correct 8 ms 5480 KB Output is correct
17 Correct 8 ms 5460 KB Output is correct
18 Correct 11 ms 5588 KB Output is correct
19 Correct 8 ms 5716 KB Output is correct
20 Correct 7 ms 5716 KB Output is correct
21 Correct 7 ms 5676 KB Output is correct
22 Correct 5 ms 5424 KB Output is correct
23 Correct 5 ms 5460 KB Output is correct
24 Correct 7 ms 5800 KB Output is correct
25 Correct 6 ms 5808 KB Output is correct
26 Correct 5 ms 6060 KB Output is correct
27 Correct 5 ms 5720 KB Output is correct
28 Correct 6 ms 5844 KB Output is correct
29 Correct 8 ms 6060 KB Output is correct
30 Correct 6 ms 5972 KB Output is correct
31 Correct 7 ms 6100 KB Output is correct
32 Correct 7 ms 5424 KB Output is correct
33 Correct 255 ms 24756 KB Output is correct
34 Correct 278 ms 23904 KB Output is correct
35 Correct 242 ms 23252 KB Output is correct
36 Correct 241 ms 24228 KB Output is correct
37 Correct 246 ms 24324 KB Output is correct
38 Correct 275 ms 24948 KB Output is correct
39 Correct 152 ms 50044 KB Output is correct
40 Correct 164 ms 50096 KB Output is correct
41 Correct 139 ms 51940 KB Output is correct
42 Correct 140 ms 34508 KB Output is correct
43 Correct 146 ms 34460 KB Output is correct
44 Correct 240 ms 24776 KB Output is correct
45 Correct 249 ms 24728 KB Output is correct
46 Correct 306 ms 28060 KB Output is correct
47 Correct 196 ms 36408 KB Output is correct
48 Correct 173 ms 33996 KB Output is correct
49 Correct 149 ms 35328 KB Output is correct
50 Correct 146 ms 21836 KB Output is correct
51 Correct 144 ms 21708 KB Output is correct
52 Correct 180 ms 36984 KB Output is correct
53 Correct 188 ms 36312 KB Output is correct
54 Correct 100 ms 50252 KB Output is correct
55 Correct 149 ms 37452 KB Output is correct
56 Correct 161 ms 47096 KB Output is correct
57 Correct 148 ms 51452 KB Output is correct
58 Correct 160 ms 47756 KB Output is correct
59 Correct 159 ms 47876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5088 KB Output is correct
2 Correct 3 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 7 ms 5460 KB Output is correct
6 Correct 7 ms 5428 KB Output is correct
7 Correct 7 ms 5460 KB Output is correct
8 Correct 7 ms 5420 KB Output is correct
9 Correct 8 ms 5404 KB Output is correct
10 Correct 7 ms 5420 KB Output is correct
11 Correct 8 ms 5460 KB Output is correct
12 Correct 7 ms 6060 KB Output is correct
13 Correct 6 ms 6100 KB Output is correct
14 Correct 7 ms 5776 KB Output is correct
15 Correct 7 ms 5716 KB Output is correct
16 Correct 8 ms 5480 KB Output is correct
17 Correct 8 ms 5460 KB Output is correct
18 Correct 11 ms 5588 KB Output is correct
19 Correct 8 ms 5716 KB Output is correct
20 Correct 7 ms 5716 KB Output is correct
21 Correct 7 ms 5676 KB Output is correct
22 Correct 5 ms 5424 KB Output is correct
23 Correct 5 ms 5460 KB Output is correct
24 Correct 7 ms 5800 KB Output is correct
25 Correct 6 ms 5808 KB Output is correct
26 Correct 5 ms 6060 KB Output is correct
27 Correct 5 ms 5720 KB Output is correct
28 Correct 6 ms 5844 KB Output is correct
29 Correct 8 ms 6060 KB Output is correct
30 Correct 6 ms 5972 KB Output is correct
31 Correct 7 ms 6100 KB Output is correct
32 Correct 7 ms 5424 KB Output is correct
33 Correct 255 ms 24756 KB Output is correct
34 Correct 278 ms 23904 KB Output is correct
35 Correct 242 ms 23252 KB Output is correct
36 Correct 241 ms 24228 KB Output is correct
37 Correct 246 ms 24324 KB Output is correct
38 Correct 275 ms 24948 KB Output is correct
39 Correct 152 ms 50044 KB Output is correct
40 Correct 164 ms 50096 KB Output is correct
41 Correct 139 ms 51940 KB Output is correct
42 Correct 140 ms 34508 KB Output is correct
43 Correct 146 ms 34460 KB Output is correct
44 Correct 240 ms 24776 KB Output is correct
45 Correct 249 ms 24728 KB Output is correct
46 Correct 306 ms 28060 KB Output is correct
47 Correct 196 ms 36408 KB Output is correct
48 Correct 173 ms 33996 KB Output is correct
49 Correct 149 ms 35328 KB Output is correct
50 Correct 146 ms 21836 KB Output is correct
51 Correct 144 ms 21708 KB Output is correct
52 Correct 180 ms 36984 KB Output is correct
53 Correct 188 ms 36312 KB Output is correct
54 Correct 100 ms 50252 KB Output is correct
55 Correct 149 ms 37452 KB Output is correct
56 Correct 161 ms 47096 KB Output is correct
57 Correct 148 ms 51452 KB Output is correct
58 Correct 160 ms 47756 KB Output is correct
59 Correct 159 ms 47876 KB Output is correct
60 Correct 2 ms 4948 KB Output is correct
61 Incorrect 3 ms 4948 KB Output isn't correct
62 Halted 0 ms 0 KB -