Submission #134605

#TimeUsernameProblemLanguageResultExecution timeMemory
134605ckodserDetecting Molecules (IOI16_molecules)C++14
100 / 100
142 ms17888 KiB
#include "molecules.h" #include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define pii pair<ll,ll> #define F first #define S second #define ld long double using namespace :: std; const ll maxn=2e5+500; const ll inf=1e9+900; ll pr[maxn]; ll sa[maxn]; vector<int> find_subset(int l, int r,vector<int> W) { vector<pii> w; for(ll i=0;i<W.size();i++){ w.pb(mp(W[i],i)); } sort(w.begin(),w.end()); ll n=w.size(); pr[0]=w[0].F; for(ll i=1;i<n;i++){ pr[i]=pr[i-1]+w[i].F; } sa[n-1]=w[n-1].F; for(ll i=n-2;i>=0;i--){ sa[i]=sa[i+1]+w[i].F; } vector<int> ans; for(ll t=1;t<=n;t++){ if(l<=pr[t-1] && pr[t-1]<=r){ for(ll i=0;i<t;i++){ ans.pb(w[i].S); } sort(ans.begin(),ans.end()); return ans; } if(l<=sa[n-t] && sa[n-t]<=r){ for(ll i=n-t;i<n;i++){ ans.pb(w[i].S); } sort(ans.begin(),ans.end()); return ans; } if(pr[t-1]<l && r<sa[n-t]){ ll sum=pr[t-1]; set<ll> hast; set<ll> nist; for(ll i=0;i<t;i++)hast.insert(i); for(ll i=t;i<n;i++)nist.insert(i); while(sum<l){ auto it=(hast.begin()); sum-=(w[*it].F); hast.erase(it); auto ip=(nist.end()); ip--; sum+=(w[*ip].F); nist.erase(ip); hast.insert(*ip); } for(auto e:hast){ ans.pb(w[e].S); } sort(ans.begin(),ans.end()); return ans; } } }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:24:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i=0;i<W.size();i++){
                ~^~~~~~~~~
molecules.cpp:78:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...