# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1008898 | jer033 | Detecting Molecules (IOI16_molecules) | C++17 | 39 ms | 10368 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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<long long, int>;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int molecule_count = w.size();
vector<pli> molecules;
molecules.reserve(molecule_count);
for (int i=0; i<molecule_count; i++)
{
molecules.push_back({w[i], i});
}
sort(molecules.begin(), molecules.end());
ll lower_bound = l;
ll upper_bound = u;
vector<ll> prefix_sums;
vector<ll> suffix_sums;
prefix_sums.reserve(molecule_count+1);
suffix_sums.reserve(molecule_count+1);
prefix_sums.push_back(0);
for (int i=0; i<molecule_count; i++)
{
prefix_sums.push_back(prefix_sums[i]+molecules[i].first);
}
suffix_sums.push_back(0);
for (int i=0; i<molecule_count; i++)
{
suffix_sums.push_back(suffix_sums[i]+molecules[molecule_count-1-i].first);
}
int ele_count = -1;
for (int i=0; i<=molecule_count; i++)
if ((prefix_sums[i]<=u) and (suffix_sums[i]>=l))
ele_count = i;
if (ele_count == -1)
return {};
vector<int> rearranged_indices;
rearranged_indices.reserve(ele_count+1);
for (int i=0; i<ele_count; i++)
rearranged_indices.push_back(i);
ll curr_sum = prefix_sums[ele_count];
int j = 0;
while (curr_sum < l)
{
rearranged_indices[j] = molecule_count-1-j;
curr_sum = curr_sum - molecules[j].first + molecules[molecule_count-1-j].first;
j++;
}
vector<int> ans;
ans.reserve(ele_count+1);
for (int i=0; i<ele_count; i++)
{
ans.push_back(molecules[rearranged_indices[i]].second);
}
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... |