# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730239 | 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, 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;
}
used[ind]=1;
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);
}
lli sum=l-ost, now=0;
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... |