# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
800516 | Boas | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 300 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()
#define loop(x) for (int i = 0; i < (x); i++)
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
vi find_subset(int l, int u, vi w)
{
vii sortedW;
loop(w.size())
{
if (w[i] > u)
continue;
sortedW.push_back({w[i], i});
}
sort(ALL(sortedW));
vi used;
bitset<MAX_N> usin;
int totalW = 0;
while (totalW < l)
{
bool added = false;
for (int i = sortedW.size() - 1; i >= 0; i--)
{
if (usin[i])
continue;
const auto &[W, ix] = sortedW[i];
if (totalW + W > u)
{
continue;
}
added = true;
used.push_back(ix);
usin[i] = true;
totalW += W;
sortedW.erase(sortedW.begin() + i);
}
if (!added)
break;
}
if (totalW >= l)
return used;
if (sortedW.size() < 2)
return {};
const auto &[W, ix] = sortedW[0];
used.push_back(ix);
totalW += W;
usin[0] = true;
vi oldUsed(used);
bitset<MAX_N> oldUsin(usin);
int oldW = totalW;
for (int i1 = 0; i1 < sortedW.size(); i1++)
{
if (used[i1])
continue;
ii p1 = sortedW[i1];
for (int i2 : oldUsed)
{
ii p2 = sortedW[i2];
used = oldUsed;
used[find(ALL(used), p2.second) - used.begin()] = p1.second;
totalW = oldW - p2.first + p1.first;
while (totalW < l)
{
bool added = false;
for (int i = sortedW.size() - 1; i >= 0; i--)
{
if (usin[i])
continue;
const auto &[W, ix] = sortedW[i];
if (totalW + W > u)
{
continue;
}
added = true;
used.push_back(ix);
usin[i] = true;
totalW += W;
sortedW.erase(sortedW.begin() + i);
}
if (!added)
break;
}
if (totalW >= l)
return used;
}
}
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... |