답안 #417623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417623 2021-06-04T04:16:45 Z maomao90 Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
1845 ms 524292 KB
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005

int n;
int h[MAXN], c[MAXN];
vi adj[MAXN];
map<int, ll> incre[MAXN];
ll ans;

void dp(int u) {
	for (int v : adj[u]) {
		dp(v);
		auto fi = incre[u], se = incre[v];
		if (fi.size() < se.size()) swap(fi, se);
		for (auto i : se) {
			fi[i.FI] += i.SE;
		}
		incre[u] = fi;
	}
	auto lower = incre[u].lower_bound(h[u]);
	if (lower != incre[u].begin()) {
		lower = prev(lower);
		int remc = c[u];
		while (1) {
			//printf("%d %lld\n", lower -> FI, lower -> SE);
			ll take = min((ll) remc, lower -> SE);
			lower -> SE -= take;
			remc -= take;
			if (lower -> SE == 0) {
				auto tmp = lower;
				bool hv = 0;
				if (tmp != incre[u].begin()) {
					tmp = prev(tmp);
					hv = 1;
				}
				incre[u].erase(lower);
				if (!hv) {
				   	break;
				} else {
					lower = tmp;
				}
			} else {
				break;
			}
		}
	}
	incre[u][h[u]] += c[u];
	//printf("%d:\n", u);
	//for (auto i : incre[u]) {
		//printf(" %d %lld\n", i.FI, i.SE);
	//}
}

int main() {
	scanf("%d", &n);
	REP (i, 1, n + 1) {
		int a; scanf("%d%d%d", &a, &h[i], &c[i]);
		ans += c[i];
		if (a != i) adj[a].pb(i);
	}
	dp(1);
	for (auto i : incre[1]) {
		ans -= i.SE;
	}
	printf("%lld\n", ans);
	return 0;
}

/*
4
1 3 4
1 1 2
2 0 3
3 2 1
*/

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
worst_reporter2.cpp:83:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |   int a; scanf("%d%d%d", &a, &h[i], &c[i]);
      |          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14300 KB Output is correct
2 Correct 10 ms 14284 KB Output is correct
3 Correct 10 ms 14392 KB Output is correct
4 Correct 11 ms 14324 KB Output is correct
5 Correct 30 ms 17132 KB Output is correct
6 Correct 20 ms 15880 KB Output is correct
7 Correct 14 ms 15360 KB Output is correct
8 Correct 27 ms 16876 KB Output is correct
9 Correct 18 ms 15832 KB Output is correct
10 Correct 15 ms 15260 KB Output is correct
11 Correct 13 ms 14916 KB Output is correct
12 Correct 98 ms 56284 KB Output is correct
13 Correct 18 ms 18816 KB Output is correct
14 Correct 69 ms 43060 KB Output is correct
15 Correct 41 ms 29572 KB Output is correct
16 Correct 23 ms 17612 KB Output is correct
17 Correct 19 ms 16128 KB Output is correct
18 Correct 12 ms 14944 KB Output is correct
19 Correct 932 ms 239760 KB Output is correct
20 Correct 54 ms 30276 KB Output is correct
21 Correct 14 ms 16204 KB Output is correct
22 Correct 1022 ms 15652 KB Output is correct
23 Correct 34 ms 14788 KB Output is correct
24 Correct 1421 ms 443856 KB Output is correct
25 Correct 53 ms 31040 KB Output is correct
26 Correct 13 ms 16328 KB Output is correct
27 Correct 933 ms 156180 KB Output is correct
28 Correct 1295 ms 302928 KB Output is correct
29 Correct 1845 ms 518996 KB Output is correct
30 Correct 1031 ms 406980 KB Output is correct
31 Correct 1020 ms 407232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14300 KB Output is correct
2 Correct 10 ms 14284 KB Output is correct
3 Correct 10 ms 14392 KB Output is correct
4 Correct 11 ms 14324 KB Output is correct
5 Correct 30 ms 17132 KB Output is correct
6 Correct 20 ms 15880 KB Output is correct
7 Correct 14 ms 15360 KB Output is correct
8 Correct 27 ms 16876 KB Output is correct
9 Correct 18 ms 15832 KB Output is correct
10 Correct 15 ms 15260 KB Output is correct
11 Correct 13 ms 14916 KB Output is correct
12 Correct 98 ms 56284 KB Output is correct
13 Correct 18 ms 18816 KB Output is correct
14 Correct 69 ms 43060 KB Output is correct
15 Correct 41 ms 29572 KB Output is correct
16 Correct 23 ms 17612 KB Output is correct
17 Correct 19 ms 16128 KB Output is correct
18 Correct 12 ms 14944 KB Output is correct
19 Correct 932 ms 239760 KB Output is correct
20 Correct 54 ms 30276 KB Output is correct
21 Correct 14 ms 16204 KB Output is correct
22 Correct 1022 ms 15652 KB Output is correct
23 Correct 34 ms 14788 KB Output is correct
24 Correct 1421 ms 443856 KB Output is correct
25 Correct 53 ms 31040 KB Output is correct
26 Correct 13 ms 16328 KB Output is correct
27 Correct 933 ms 156180 KB Output is correct
28 Correct 1295 ms 302928 KB Output is correct
29 Correct 1845 ms 518996 KB Output is correct
30 Correct 1031 ms 406980 KB Output is correct
31 Correct 1020 ms 407232 KB Output is correct
32 Correct 33 ms 17100 KB Output is correct
33 Correct 1517 ms 156224 KB Output is correct
34 Correct 758 ms 93376 KB Output is correct
35 Correct 1666 ms 158932 KB Output is correct
36 Correct 746 ms 93088 KB Output is correct
37 Correct 291 ms 44488 KB Output is correct
38 Correct 223 ms 33788 KB Output is correct
39 Runtime error 959 ms 524292 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14300 KB Output is correct
2 Correct 10 ms 14284 KB Output is correct
3 Correct 10 ms 14392 KB Output is correct
4 Correct 11 ms 14324 KB Output is correct
5 Correct 30 ms 17132 KB Output is correct
6 Correct 20 ms 15880 KB Output is correct
7 Correct 14 ms 15360 KB Output is correct
8 Correct 27 ms 16876 KB Output is correct
9 Correct 18 ms 15832 KB Output is correct
10 Correct 15 ms 15260 KB Output is correct
11 Correct 13 ms 14916 KB Output is correct
12 Correct 98 ms 56284 KB Output is correct
13 Correct 18 ms 18816 KB Output is correct
14 Correct 69 ms 43060 KB Output is correct
15 Correct 41 ms 29572 KB Output is correct
16 Correct 23 ms 17612 KB Output is correct
17 Correct 19 ms 16128 KB Output is correct
18 Correct 12 ms 14944 KB Output is correct
19 Correct 932 ms 239760 KB Output is correct
20 Correct 54 ms 30276 KB Output is correct
21 Correct 14 ms 16204 KB Output is correct
22 Correct 1022 ms 15652 KB Output is correct
23 Correct 34 ms 14788 KB Output is correct
24 Correct 1421 ms 443856 KB Output is correct
25 Correct 53 ms 31040 KB Output is correct
26 Correct 13 ms 16328 KB Output is correct
27 Correct 933 ms 156180 KB Output is correct
28 Correct 1295 ms 302928 KB Output is correct
29 Correct 1845 ms 518996 KB Output is correct
30 Correct 1031 ms 406980 KB Output is correct
31 Correct 1020 ms 407232 KB Output is correct
32 Correct 33 ms 17100 KB Output is correct
33 Correct 1517 ms 156224 KB Output is correct
34 Correct 758 ms 93376 KB Output is correct
35 Correct 1666 ms 158932 KB Output is correct
36 Correct 746 ms 93088 KB Output is correct
37 Correct 291 ms 44488 KB Output is correct
38 Correct 223 ms 33788 KB Output is correct
39 Runtime error 959 ms 524292 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -