Submission #730236

#TimeUsernameProblemLanguageResultExecution timeMemory
730236ETheBest3Detecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> //#include "molecules.h" #define lli int using namespace std; vector<lli> ans; vector<pair<lli, lli>> W; lli N; 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, ll=0, rr=N, 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; } 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); } if(l-ost+W[maxl].first-W[ans[ans.size()-1]].first<=u){ ans[ans.size()-1]=W[maxl].second; return ans; } return vector<int>(0); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(lli i=0; i<w.size(); i++)W.push_back({w[i], i});
      |                  ~^~~~~~~~~
molecules.cpp:23:32: warning: unused variable 'll' [-Wunused-variable]
   23 |     lli ost=l, ind=0, last=-1, ll=0, rr=N, maxl=-1;
      |                                ^~
molecules.cpp:23:38: warning: unused variable 'rr' [-Wunused-variable]
   23 |     lli ost=l, ind=0, last=-1, ll=0, rr=N, maxl=-1;
      |                                      ^~
#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...