This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "molecules.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
vector<int> ans;
vector<pair<long long,int> > vec;
void process(long long j,long long i){
for (long long idx = j; idx <= i ; ++idx)
ans.push_back(vec[idx].se);
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vec.resize(w.size());
for (long long i = 0; i < w.size(); ++i)
{
vec[i].fi=w[i];
vec[i].se=i;
}
sort(vec.begin(),vec.end());
if(vec[0].fi>=l&&vec[0].fi<=u){
process(0,0);
return ans;
}
for (long long i = 1; i < w.size(); ++i){
vec[i].fi+=vec[i-1].fi;
if(vec[i].fi>=l&&vec[i].fi<=u){
process(0,i);
return ans;
}
}
/*cout<<"\n";
for (long long i = 0; i < w.size(); ++i)
{
cout<<vec[i].fi<<" ";
}
cout<<"\n";*/
for (long long i = 0; i < w.size(); ++i)
{
if(vec[i].fi>u){
auto search=lower_bound(vec.begin(),vec.begin()+i,make_pair(vec[i].fi-l,0));
//debugs(vec[i].fi,search-vec.begin());
if(search==vec.begin()+i) continue;
//debugs(vec[i].fi-l,(vec[i].fi-search->fi));
if((vec[i].fi-search->fi)>=l&&(vec[i].fi-search->fi)<=u){
process((search-vec.begin())+1,i);
return ans;
}
if(search!=vec.begin()){
search--;
}
if((vec[i].fi-search->fi)>=l&&(vec[i].fi-search->fi)<=u){
process((search-vec.begin())+1,i);
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:14:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (long long i = 0; i < w.size(); ++i)
~~^~~~~~~~~~
molecules.cpp:24:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (long long i = 1; i < w.size(); ++i){
~~^~~~~~~~~~
molecules.cpp:37:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (long long i = 0; i < w.size(); ++i)
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |