제출 #730243

#제출 시각아이디문제언어결과실행 시간메모리
730243ETheBest3Detecting 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; bool fl=0; while(ost>0){ ind=bin_search(last+1, N, ost); if(ind==-1){ break; } used[ind]=1; ans.push_back(W[ind].second); ost-=W[ind].first; last=ind; } if(ost==0)return ans; if(ans.size()==0){ if(W[N-1].first<=u){ ans.push_back(W[N-1].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; }

컴파일 시 표준 에러 (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});
      |                  ~^~~~~~~~~
molecules.cpp:25:10: warning: unused variable 'fl' [-Wunused-variable]
   25 |     bool fl=0;
      |          ^~
#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...