# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338712 | markussie | Detecting Molecules (IOI16_molecules) | C++17 | 74 ms | 6508 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 "molecules.h"
#include <algorithm>
#include <vector>
#include <numeric>
#include <deque>
using namespace std;
bool intersect(int64_t a, int64_t b, int64_t x, int64_t y)
{
return a >= x && a <= y || x >= a && x <= b;
}
std::vector<int> find_subset(int d, int u, std::vector<int> w)
{
int n = w.size();
vector<int> ind(n);
iota(ind.begin(), ind.end(), 0);
sort(ind.begin(), ind.end(), [&](int lhs, int rhs) {return w[lhs] < w[rhs];});
vector<int64_t> sum(n+1);
for(int i = 1; i <= n; ++i)
sum[i] = sum[i-1] + w[ind[i-1]];
for(int i = 0; i < w.size(); ++i)
{
int l = 1, r = w.size()-i+1;
while(r - l > 1)
{
int mid = (l + r) / 2;
int64_t mn;
mn = 1LL * w[ind[i]] * mid + sum[i+mid] - sum[i] - 1LL * mid*w[ind[i]];
if(mn > u)
r = mid;
else
l = mid;
}
int64_t mn, mx;
mn = 1LL * w[ind[i]] * l + sum[i+l] - sum[i] - 1LL * l * w[ind[i]];
mx = 1LL * w[ind[i]] * l + sum[n] - sum[n-l+1] - 1LL * (l-1) * w[ind[i]];
if(intersect(d, u, mn, mx))
{
int64_t cur_sum = 0;
deque<int> tmp;
for(int j = 0; j < l; ++j)
tmp.push_back(ind[i+j]), cur_sum += w[ind[i+j]];
int it = n-1;
while(cur_sum < d)
{
cur_sum -= w[tmp.front()];
tmp.pop_front();
cur_sum += w[ind[it]];
tmp.push_back(ind[it]);
--it;
}
vector<int> ans(tmp.begin(), tmp.end());
return ans;
}
}
return {};
}
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... |