# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
780660 | JoenPoenMan | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 212 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;
#define ALL(arr) begin(arr), end(arr)
typedef pair<int, int> ii;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<bool> subset(w.size(), false);
vector<ii> sw;
for (int i = 0; i < w.size(); i++) {
sw.push_back({w[i], i});
}
sort(ALL(sw));
int sum = 0;
vector<int> blacklist;
for (int attempts = w.size(); attempts >= 0; attempts--) {
if (sum < l) {
bool suc = false;
for (auto [weight, ind] : sw) if (!(subset[ind] || find(ALL(blacklist), ind) != blacklist.end())) {
if (sum + weight >= l) {
subset[ind] = true;
sum += weight;
suc = true;
break;
}
}
if (!suc) {
for (int i = 0; i < sw.size(); i++) if (!(subset[sw[i].second] || find(ALL(blacklist), sw[i].second) != blacklist.end())) {
auto [weight, ind] = sw[i];
subset[ind] = true;
sum += weight;
break;
}
}
} else if (sum > u) {
bool suc = false;
for (auto [weight, ind] : sw) if (subset[ind]) {
if (sum - weight <= u) {
blacklist.push_back(ind);
subset[ind] = false;
sum -= weight;
suc = true;
break;
}
}
if (!suc) {
for (int i = 0; i < sw.size(); i++) if (subset[sw[i].second]) {
auto [weight, ind] = sw[i];
blacklist.push_back(ind);
subset[ind] = false;
sum -= weight;
break;
}
}
} else {
vector<int> res;
for (int n = 0; n < subset.size(); n++) if (subset[n]) res.push_back(n);
return res;
}
}
return std::vector<int>(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... |