# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785655 | Boas | Detecting Molecules (IOI16_molecules) | C++17 | 1077 ms | 308 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"
using namespace std;
#include <bits/stdc++.h>
#define MAX_N 200001
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
int L{};
int U{};
int n{};
vi mols;
vi addMolecule(const int &i, const int &w, const unordered_set<int> &used)
{
if (i >= mols.size())
{
return {};
}
int nw = w + mols[i];
if (nw > U)
{
return addMolecule(i + 1, w, used);
}
if (nw >= L)
{
vi solution(ALL(used));
solution.push_back(i);
return solution;
}
auto dontAdd = addMolecule(i + 1, w, used);
if (dontAdd.size() > 0)
return dontAdd;
unordered_set<int> newUsed(used);
newUsed.insert(i);
auto add = addMolecule(i + 1, nw, newUsed);
if (add.size() > 0)
return add;
return {};
}
vi find_subset(int l, int u, vi w)
{
n = w.size();
bool allSame = true;
for (int i = 1; i < n; i++)
{
if (w[i] != w[i - 1])
{
allSame = false;
break;
}
}
if (allSame)
{
int s = 0;
int i = 0;
vi res;
for (int i = 0; i < n; i++)
{
s += w[0];
res.push_back(i);
if (s > u)
break;
if (s >= l)
return res;
}
return {};
}
L = l;
U = u;
mols = w;
return addMolecule(0, 0, {});
}
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... |