Submission #417614

# Submission time Handle Problem Language Result Execution time Memory
417614 2021-06-04T03:59:08 Z maomao90 Worst Reporter 4 (JOI21_worst_reporter4) C++17
0 / 100
10 ms 14400 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, int> 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].upper_bound(h[u]);
	if (lower != incre[u].begin()) {
		lower = prev(lower);
		int remc = c[u];
		while (1) {
			int take = min(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(tmp);
				if (!hv) {
				   	break;
				} else {
					lower = tmp;
				}
			} else {
				break;
			}
		}
	}
	incre[u][h[u]] += c[u];
}

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;
}

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
worst_reporter2.cpp:78:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |   int a; scanf("%d%d%d", &a, &h[i], &c[i]);
      |          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14284 KB Output is correct
2 Correct 10 ms 14392 KB Output is correct
3 Incorrect 10 ms 14400 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14284 KB Output is correct
2 Correct 10 ms 14392 KB Output is correct
3 Incorrect 10 ms 14400 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14284 KB Output is correct
2 Correct 10 ms 14392 KB Output is correct
3 Incorrect 10 ms 14400 KB Output isn't correct
4 Halted 0 ms 0 KB -