Submission #417630

# Submission time Handle Problem Language Result Execution time Memory
417630 2021-06-04T04:44:25 Z maomao90 Worst Reporter 4 (JOI21_worst_reporter4) C++17
79 / 100
392 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);
		if (incre[v].size() > incre[u].size()) swap(incre[v], incre[u]);
		for (auto i : incre[v]) {
			incre[u][i.FI] += i.SE;
		}
	}
	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:79:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
worst_reporter2.cpp:81:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |   int a; scanf("%d%d%d", &a, &h[i], &c[i]);
      |          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14284 KB Output is correct
2 Correct 10 ms 14336 KB Output is correct
3 Correct 10 ms 14336 KB Output is correct
4 Correct 9 ms 14392 KB Output is correct
5 Correct 15 ms 15416 KB Output is correct
6 Correct 14 ms 15044 KB Output is correct
7 Correct 13 ms 14836 KB Output is correct
8 Correct 16 ms 15500 KB Output is correct
9 Correct 14 ms 14924 KB Output is correct
10 Correct 13 ms 14796 KB Output is correct
11 Correct 13 ms 14668 KB Output is correct
12 Correct 14 ms 15200 KB Output is correct
13 Correct 13 ms 15236 KB Output is correct
14 Correct 13 ms 14960 KB Output is correct
15 Correct 13 ms 14952 KB Output is correct
16 Correct 16 ms 15816 KB Output is correct
17 Correct 14 ms 15200 KB Output is correct
18 Correct 12 ms 14672 KB Output is correct
19 Correct 14 ms 15180 KB Output is correct
20 Correct 12 ms 14924 KB Output is correct
21 Correct 12 ms 14924 KB Output is correct
22 Correct 13 ms 15072 KB Output is correct
23 Correct 12 ms 14736 KB Output is correct
24 Correct 14 ms 15180 KB Output is correct
25 Correct 15 ms 15044 KB Output is correct
26 Correct 27 ms 15180 KB Output is correct
27 Correct 14 ms 15216 KB Output is correct
28 Correct 16 ms 15180 KB Output is correct
29 Correct 14 ms 15308 KB Output is correct
30 Correct 14 ms 15308 KB Output is correct
31 Correct 14 ms 15404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14284 KB Output is correct
2 Correct 10 ms 14336 KB Output is correct
3 Correct 10 ms 14336 KB Output is correct
4 Correct 9 ms 14392 KB Output is correct
5 Correct 15 ms 15416 KB Output is correct
6 Correct 14 ms 15044 KB Output is correct
7 Correct 13 ms 14836 KB Output is correct
8 Correct 16 ms 15500 KB Output is correct
9 Correct 14 ms 14924 KB Output is correct
10 Correct 13 ms 14796 KB Output is correct
11 Correct 13 ms 14668 KB Output is correct
12 Correct 14 ms 15200 KB Output is correct
13 Correct 13 ms 15236 KB Output is correct
14 Correct 13 ms 14960 KB Output is correct
15 Correct 13 ms 14952 KB Output is correct
16 Correct 16 ms 15816 KB Output is correct
17 Correct 14 ms 15200 KB Output is correct
18 Correct 12 ms 14672 KB Output is correct
19 Correct 14 ms 15180 KB Output is correct
20 Correct 12 ms 14924 KB Output is correct
21 Correct 12 ms 14924 KB Output is correct
22 Correct 13 ms 15072 KB Output is correct
23 Correct 12 ms 14736 KB Output is correct
24 Correct 14 ms 15180 KB Output is correct
25 Correct 15 ms 15044 KB Output is correct
26 Correct 27 ms 15180 KB Output is correct
27 Correct 14 ms 15216 KB Output is correct
28 Correct 16 ms 15180 KB Output is correct
29 Correct 14 ms 15308 KB Output is correct
30 Correct 14 ms 15308 KB Output is correct
31 Correct 14 ms 15404 KB Output is correct
32 Correct 16 ms 15436 KB Output is correct
33 Correct 392 ms 73600 KB Output is correct
34 Correct 321 ms 48740 KB Output is correct
35 Correct 386 ms 70504 KB Output is correct
36 Correct 313 ms 48968 KB Output is correct
37 Correct 218 ms 29680 KB Output is correct
38 Correct 187 ms 25400 KB Output is correct
39 Correct 173 ms 50360 KB Output is correct
40 Correct 158 ms 50884 KB Output is correct
41 Correct 121 ms 50884 KB Output is correct
42 Correct 170 ms 36852 KB Output is correct
43 Correct 156 ms 36748 KB Output is correct
44 Correct 359 ms 99084 KB Output is correct
45 Correct 258 ms 63360 KB Output is correct
46 Correct 109 ms 25804 KB Output is correct
47 Correct 270 ms 46836 KB Output is correct
48 Correct 140 ms 39984 KB Output is correct
49 Correct 114 ms 39812 KB Output is correct
50 Correct 304 ms 42372 KB Output is correct
51 Correct 113 ms 29708 KB Output is correct
52 Correct 307 ms 47720 KB Output is correct
53 Correct 133 ms 40432 KB Output is correct
54 Correct 132 ms 50812 KB Output is correct
55 Correct 226 ms 49292 KB Output is correct
56 Correct 207 ms 55264 KB Output is correct
57 Correct 186 ms 58256 KB Output is correct
58 Correct 220 ms 55552 KB Output is correct
59 Correct 225 ms 55528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14284 KB Output is correct
2 Correct 10 ms 14336 KB Output is correct
3 Correct 10 ms 14336 KB Output is correct
4 Correct 9 ms 14392 KB Output is correct
5 Correct 15 ms 15416 KB Output is correct
6 Correct 14 ms 15044 KB Output is correct
7 Correct 13 ms 14836 KB Output is correct
8 Correct 16 ms 15500 KB Output is correct
9 Correct 14 ms 14924 KB Output is correct
10 Correct 13 ms 14796 KB Output is correct
11 Correct 13 ms 14668 KB Output is correct
12 Correct 14 ms 15200 KB Output is correct
13 Correct 13 ms 15236 KB Output is correct
14 Correct 13 ms 14960 KB Output is correct
15 Correct 13 ms 14952 KB Output is correct
16 Correct 16 ms 15816 KB Output is correct
17 Correct 14 ms 15200 KB Output is correct
18 Correct 12 ms 14672 KB Output is correct
19 Correct 14 ms 15180 KB Output is correct
20 Correct 12 ms 14924 KB Output is correct
21 Correct 12 ms 14924 KB Output is correct
22 Correct 13 ms 15072 KB Output is correct
23 Correct 12 ms 14736 KB Output is correct
24 Correct 14 ms 15180 KB Output is correct
25 Correct 15 ms 15044 KB Output is correct
26 Correct 27 ms 15180 KB Output is correct
27 Correct 14 ms 15216 KB Output is correct
28 Correct 16 ms 15180 KB Output is correct
29 Correct 14 ms 15308 KB Output is correct
30 Correct 14 ms 15308 KB Output is correct
31 Correct 14 ms 15404 KB Output is correct
32 Correct 16 ms 15436 KB Output is correct
33 Correct 392 ms 73600 KB Output is correct
34 Correct 321 ms 48740 KB Output is correct
35 Correct 386 ms 70504 KB Output is correct
36 Correct 313 ms 48968 KB Output is correct
37 Correct 218 ms 29680 KB Output is correct
38 Correct 187 ms 25400 KB Output is correct
39 Correct 173 ms 50360 KB Output is correct
40 Correct 158 ms 50884 KB Output is correct
41 Correct 121 ms 50884 KB Output is correct
42 Correct 170 ms 36852 KB Output is correct
43 Correct 156 ms 36748 KB Output is correct
44 Correct 359 ms 99084 KB Output is correct
45 Correct 258 ms 63360 KB Output is correct
46 Correct 109 ms 25804 KB Output is correct
47 Correct 270 ms 46836 KB Output is correct
48 Correct 140 ms 39984 KB Output is correct
49 Correct 114 ms 39812 KB Output is correct
50 Correct 304 ms 42372 KB Output is correct
51 Correct 113 ms 29708 KB Output is correct
52 Correct 307 ms 47720 KB Output is correct
53 Correct 133 ms 40432 KB Output is correct
54 Correct 132 ms 50812 KB Output is correct
55 Correct 226 ms 49292 KB Output is correct
56 Correct 207 ms 55264 KB Output is correct
57 Correct 186 ms 58256 KB Output is correct
58 Correct 220 ms 55552 KB Output is correct
59 Correct 225 ms 55528 KB Output is correct
60 Runtime error 246 ms 524292 KB Execution killed with signal 9
61 Halted 0 ms 0 KB -