# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1132194 | lopkus | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 324 KiB |
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
sort(w.begin(), w.end());
int n = w.size();
for(int i = 0; i < n; i++) {
if(w[i] >= l && w[i] <= u) {
return {w[i]};
}
}
int idx = - 1;
for(int i = 0; i < n; i++) {
if(w[i] < l) {
idx = i;
}
}
if(idx == - 1) {
return {};
}
vector<int> p;
for(int i = idx; i >= 0; i--) {
if(u - l >= w[idx] - w[i]) {
p.push_back(w[i]);
}
}
sort(p.begin(), p.end());
vector<int> ans;
vector<int> was(n, 0);
while(l > 0) {
int o = - 1;
for(int i = 0; i < p.size(); i++) {
if(was[i]) {
continue;
}
if(p[i] >= l && p[i] <= u) {
o = p[i];
break;
}
}
if(o != - 1) {
ans.push_back(o);
return ans;
}
for(int i = 0; i < p.size(); i++) {
if(was[i]) {
continue;
}
if(p[i] < l) {
o = i;
}
}
if(o == - 1) {
return {};
}
l -= p[o];
u -= p[o];
was[o] = 1;
ans.push_back(p[o]);
}
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... |