제출 #914508

#제출 시각아이디문제언어결과실행 시간메모리
914508Tuanlinh123Worst Reporter 4 (JOI21_worst_reporter4)C++17
79 / 100
345 ms104616 KiB
#include<bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define fi first #define se second using namespace std; const ll maxn=200005; ll A[maxn], H[maxn], C[maxn], deg[maxn]; map<ll, ll> cnt[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, sum=0; cin >> n; for (ll i=1; i<=n; i++) cin>>A[i]>>H[i]>>C[i], sum+=C[i], deg[A[i]]++; queue <ll> q; for (ll i=1; i<=n; i++) if (!deg[i]) q.push(i); auto Merge=[&](map<ll, ll> &a, map<ll, ll> &b) { if (a.size()<b.size()) swap(a, b); for (pll i:b) a[i.fi]+=i.se; }; auto Fix=[&](map<ll, ll> &a, ll H, ll C) { a[H]+=C; auto it=a.lower_bound(H); while (it!=a.begin()) { it--; if ((*it).se>C) {(*it).se-=C; break;} C-=(*it).se; it=a.erase(it); } }; while (!q.empty()) { ll u=q.front(), crr=C[u]; q.pop(); deg[A[u]]--; Fix(cnt[u], H[u], C[u]); Merge(cnt[A[u]], cnt[u]); if (!deg[A[u]]) q.push(A[u]); } for (ll i=1; i<=n; i++) { if (!deg[i]) continue; deg[i]=0; map <ll, ll> all=cnt[i], cn; cn[H[i]]+=C[i]; for (ll crr=A[i]; crr!=i; crr=A[crr]) Merge(all, cnt[crr]), deg[crr]=0; for (pll j:cn) Fix(all, j.fi, j.se); for (pll j:all) sum-=j.se; } cout << sum << "\n"; }

컴파일 시 표준 에러 (stderr) 메시지

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:38:25: warning: unused variable 'crr' [-Wunused-variable]
   38 |         ll u=q.front(), crr=C[u]; q.pop();
      |                         ^~~
worst_reporter2.cpp:46:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   46 |         if (!deg[i]) continue; deg[i]=0;
      |         ^~
worst_reporter2.cpp:46:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   46 |         if (!deg[i]) continue; deg[i]=0;
      |                                ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...