Submission #831326

#TimeUsernameProblemLanguageResultExecution timeMemory
831326SupersonicDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms300 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n=w.size(); int ls[n];int rs[n]; vector<pair<int,int>> s; for(int i=0;i<n;i++)s.push_back({w[i],i}); sort(s.begin(),s.end()); ls[0]=s[0].first;rs[0]=s[n-1].first; int b=-1; if(ls[0]<=l&&u<=rs[0])b=0; if(ls[0]>=l&&ls[0]<=u)b=0; if(rs[0]>=l&&rs[0]<=u)b=0; for(int i=1;i<n;i++){ ls[i]=ls[i-1]+s[i].first;rs[i]=rs[i-1]+s[n-1-i].first; if(ls[i]<=l&&u<=rs[i])b=i; if(ls[i]>=l&&ls[i]<=u)b=i; if(rs[i]>=l&&rs[i]<=u)b=i; //cerr<<ls[i]<<' '<<rs[i]<<endl; } //cerr<<b<<endl; if(b==-1)return {}; vector<pair<int,int>> rr; int lp=0; for(int i=0;i<=b;i++){rr.push_back(s[i]);lp+=s[i].first;} int ci=0; int ib=b; while(lp<l){ while(b<s.size()){ lp-=rr[ci].first; rr[ci]=s[b];lp+=s[b].first;b++; if(lp>=l)break; } if(lp>=l)break; ci++;ib++;b=ib;s.pop_back(); } vector<int> r; for(auto i:rr)r.push_back(i.second); return r; } //6 7 8 8

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:30:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |       while(b<s.size()){
      |             ~^~~~~~~~~
#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...