# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784971 | Boas | Detecting Molecules (IOI16_molecules) | C++17 | 1083 ms | 2772 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
typedef vector<int> vi;
int L{};
int U{};
int n{};
vi mols;
vi addMolecule(const int &w, const bitset<MAX_N> &used)
{
for (int i = 0; i < n; i++)
{
int nw = w + mols[i];
if (nw > U)
continue;
if (used[i])
continue;
if (nw >= L)
{
vi solution = {i};
for (int i = 0; i < mols.size(); i++)
{
if (used[i])
solution.push_back(i);
}
return solution;
}
bitset<MAX_N> newUsed(used);
newUsed[i] = true;
auto ret = addMolecule(nw, newUsed);
if (ret.size() > 0)
return ret;
}
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, {});
}
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... |