# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132457 | bogdan10bos | Detecting Molecules (IOI16_molecules) | C++14 | 68 ms | 6512 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.
/// inapt
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<int> find_subset(int l, int u, vector<int> w)
{
vector<int> ord;
for(int i = 0; i < w.size(); i++) ord.push_back(i);
sort(ord.begin(), ord.end(),
[&](int a, int b) { return w[a] < w[b]; } );
vector<LL> sum(w.size());
LL s = 0;
for(int i = 0; i < w.size(); i++)
{
s += w[ ord[i] ];
sum[i] = s;
}
vector<int> ans;
if(l <= s && s <= u)
{
sort(ord.begin(), ord.end());
return ord;
}
int L = l, R = u, N = w.size();
for(int i = 0; i < w.size(); i++)
{
if(sum[i] > R) break;
//if(s - sum[N - i - 2] < L) continue;
int lgt = i + 1;
int st = 0, dr = N - lgt;
while(st <= dr)
{
int mij = st + (dr - st) / 2;
LL ss = sum[mij + lgt - 1];
if(mij > 0) ss -= sum[mij - 1];
if(ss <= R)
{
if(ss >= L)
{
int j = mij;
for(int k = j; k < j + lgt; k++) ans.push_back(ord[k]);
sort(ans.begin(), ans.end());
return ans;
}
st = mij + 1;
}
else
dr = mij - 1;
}
}
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... |