Submission #730241

#TimeUsernameProblemLanguageResultExecution timeMemory
730241ETheBest3Detecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> //#include "molecules.h" #define lli int using namespace std; vector<lli> ans; vector<pair<lli, lli>> W; lli N; bool used[200005]; lli bin_search(lli l, lli r, lli x){ if(l==r)return -1; while(l<r-1){ lli mid=(l+r)/2; if(W[mid].first>x)l=mid; else r=mid; } if(W[l].first<=x)return l; if(W[r].first>x or r>=N)return -1; return r; } std::vector<int> find_subset(int l, int u, std::vector<int> w) { for(lli i=0; i<w.size(); i++)W.push_back({w[i], i}); sort(W.begin(), W.end(), greater<pair<lli, lli>>()); N=W.size(); lli ost=l, ind=0, last=-1, maxl=-1; bool fl=0; while(ost>0){ ind=bin_search(last+1, N, ost); if(ind==-1){ if(maxl==-1)maxl=last+1; break; } used[ind]=1; ans.push_back(W[ind].second); ost-=W[ind].first; if(last!=ind-1 and fl==0){ maxl=ind-1; fl=1; } last=ind; } if(maxl==-1)return std::vector<int>(0); if(ost==0)return ans; if(ans.size()==0){ if(W[maxl].first<=u){ ans.push_back(W[maxl].second); return ans; } return vector<int>(0); } lli sum=l-ost, now=0; for(lli i=N-1; i>=0; i--){ if(used[i])continue; if(sum+W[i].first<=u and sum+W[i].first>=l){ ans.push_back(W[i].second); return ans; } } for(lli i=0; i<N; i++){ if(used[i])continue; sum+=W[i].first-w[ans[ans.size()-1-now]]; ans[ans.size()-1-now]=W[i].second; now++; if(sum>=l)break; } if(sum<l or sum>u)return vector<int>(0); return ans; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(lli i=0; i<w.size(); i++)W.push_back({w[i], 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...
#Verdict Execution timeMemoryGrader output
Fetching results...