# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730243 | ETheBest3 | Detecting Molecules (IOI16_molecules) | C++14 | 1 ms | 340 KiB |
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<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;
}
Compilation message (stderr)
# | 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... |