Submission #1027893

#TimeUsernameProblemLanguageResultExecution timeMemory
1027893AbitoJobs (BOI24_jobs)C++17
0 / 100
34 ms9812 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt #define int long long #define ll long long #define y1 YONE typedef unsigned long long ull; using namespace std; const int N=3e5+5; int a[N],n,dp[N],c[N],p[N]; vector<vector<int>> v; int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n>>a[0]; int ans=a[0]; for (int i=1;i<=n;i++){ cin>>a[i]>>p[i]; c[p[i]]=i; } for (int i=1;i<=n;i++){ if (p[i]) continue; vector<int> b; b.pb(a[i]); int x=i; while (c[x]){ x=c[x]; b.pb(a[x]); } vector<int> d; for (int i=0;i<b.size();i++){ if (!b[i]) continue; int r=i,x=0; for (int j=i;j<b.size();j++){ if (!b[j]) continue; if (b[j]<0 && b[i]<0) r=j,x+=b[j]; elif (b[j]>0 && b[i]>0) r=j,x+=b[j]; else break; } d.pb(x); i=r; } if (d.empty()) continue; if (d[0]>0){ ans+=d[0]; d.erase(d.begin()); } if (d.empty()) continue; if (d.back()<0) d.ppb(); if (d.empty()) continue; reverse(d.begin(),d.end()); v.pb(d); //for (auto u:d) cout<<u<<' ';cout<<endl; } set<vector<int>> s; for (int i=0;i<v.size();i++){ int sz=v[i].size(); s.ep({v[i][sz-1],v[i][sz-1]+v[i][sz-2],i}); } while (!s.empty()){ vector<int> x=*--s.end(); s.erase(--s.end()); if (ans+x[0]<0 || x[1]<0) continue; ans+=x[1]; v[x[2]].ppb(); v[x[2]].ppb(); if (v[x[2]].empty()) continue; int sz=v[x[2]].size(); s.ep({v[x[2]][sz-1],v[x[2]][sz-2]+v[x[2]][sz-1],x[2]}); } cout<<ans-a[0]<<endl; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:37:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (int i=0;i<b.size();i++){
      |                      ~^~~~~~~~~
Main.cpp:40:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for (int j=i;j<b.size();j++){
      |                          ~^~~~~~~~~
Main.cpp:62:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i=0;i<v.size();i++){
      |                  ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...