Submission #551163

#TimeUsernameProblemLanguageResultExecution timeMemory
551163pavementWorst Reporter 4 (JOI21_worst_reporter4)C++17
79 / 100
367 ms135612 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif #define int long long #define mp make_pair #define mt make_tuple #define pb push_back #define ppb pop_back #define eb emplace_back #define g0(a) get<0>(a) #define g1(a) get<1>(a) #define g2(a) get<2>(a) #define g3(a) get<3>(a) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using db = double; using ll = long long; using ld = long double; using ii = pair<int, int>; using iii = tuple<int, int, int>; using iiii = tuple<int, int, int, int>; template<class key, class value = null_type, class cmp = less<key> > using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; int N, idx, totC, totR, A[200005], H[200005], C[200005]; vector<int> adj[200005]; set<iii> S[200005]; void dp(int n, int e = -1) { for (auto u : adj[n]) if (u != e) { dp(u, n); if (S[u].size() > S[n].size()) swap(S[n], S[u]); for (auto i : S[u]) S[n].insert(i); } vector<set<iii>::iterator> to_del; auto it = S[n].upper_bound(mt(H[n], LLONG_MAX, LLONG_MAX)); for (int bal = C[n]; bal > 0 && it != S[n].end(); it++) { auto [h, c, tmp] = *it; if (bal > c) { to_del.pb(it); bal -= c; } else if (bal == c) { to_del.pb(it); bal = 0; } else { to_del.pb(it); S[n].insert(mt(h, c - bal, ++idx)); bal = 0; } } S[n].insert(mt(H[n], C[n], ++idx)); for (auto i : to_del) S[n].erase(i); } main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i] >> H[i] >> C[i]; H[i] = -H[i]; if (i > 1) adj[A[i]].pb(i); totC += C[i]; } // solving tree case dp(1); for (auto [a, b, c] : S[1]) totR += b; cout << totC - totR << '\n'; }

Compilation message (stderr)

worst_reporter2.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...