Submission #417268

#TimeUsernameProblemLanguageResultExecution timeMemory
417268huangqrWorst Reporter 4 (JOI21_worst_reporter4)C++14
79 / 100
358 ms524292 KiB
#ifdef local #define debug(x) cout<<#x<<" "<<x<<endl; #else #define debug(x) #endif #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pl; const ll mod=1e9+7,lim=2e5+5,bitlim=15,inf=1e9; vector<ll>adjl[lim]; ll pwr[lim],cost[lim]; map<ll,ll> *mps[lim]; void dp(ll pos){ if(adjl[pos].size() == 0){ debug(pos); mps[pos] = new map<ll,ll>(); mps[pos]->operator[](0)=0; mps[pos]->operator[](pwr[pos] + 1) = cost[pos]; debug("finished"); debug(pos); } else{ debug(pos); ll maxsz=0,maxszidx=0; for(int i=0;i<adjl[pos].size();i++){ ll u=adjl[pos][i]; dp(u); if(mps[u]->size()>maxsz){ maxsz=mps[u]->size(); maxszidx=u; } } debug(pos); mps[pos] = mps[maxszidx]; for(int i=0;i<adjl[pos].size();i++){ debug(i); ll u=adjl[pos][i]; if(u==maxszidx)continue; debug(u); debug(mps[u]->size()); for(auto p:*mps[u]){ ll k,v; tie(k,v)=p; debug("before add"); mps[pos]->operator[](k)+=v; debug("after add"); } } debug("nxt step"); mps[pos]->operator[](0) += cost[pos]; mps[pos]->operator[](pwr[pos] + 1) += cost[pos]; auto it=mps[pos]->upper_bound(pwr[pos]); ll rem=cost[pos]; debug("before rem"); while(rem>0){ it--; if(rem<=it->second)it->second-=rem,rem=0; else rem-=it->second,it=mps[pos]->erase(it); } debug("after rem"); } return; } int main(){ ios_base::sync_with_stdio(0),cin.tie(NULL); ll n; cin>>n; for(int i=1;i<=n;i++){ ll a; cin>>a>>pwr[i]>>cost[i]; if(i!=a)adjl[a].push_back(i); } dp(1); cout<<mps[1]->begin()->second<<"\n"; return 0; }

Compilation message (stderr)

worst_reporter2.cpp: In function 'void dp(ll)':
worst_reporter2.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i=0;i<adjl[pos].size();i++){
      |               ~^~~~~~~~~~~~~~~~~
worst_reporter2.cpp:30:21: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   30 |    if(mps[u]->size()>maxsz){
      |       ~~~~~~~~~~~~~~^~~~~~
worst_reporter2.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i=0;i<adjl[pos].size();i++){
      |               ~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...