# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
436547 | 2qbingxuan | Detecting Molecules (IOI16_molecules) | C++14 | 1037 ms | 5724 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;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
// l / w_min
vector<int> id(n);
iota(id.begin(), id.end(), 0);
if (long long sum = accumulate(w.begin(), w.end(), 0LL); l <= sum && sum <= u) {
return id;
}
sort(id.begin(), id.end(), [&w](size_t a, size_t b) { return w[a] < w[b]; });
vector<int> W(n);
for (int i = 0; i < n; i++) W[i] = w[id[i]];
vector<long long> pre(n+1), suf(n+2);
for (int i = 1; i <= n; i++) pre[i] = pre[i-1] + W[i-1];
for (int i = n; i >= 1; i--) suf[i] = suf[i+1] + W[i-1];
long long sum = 0;
for (int i = 0; i <= n; i++) {
for (int j = n+1; j > i; j--) {
if (l <= pre[i] + suf[j] && pre[i] + suf[j] <= u) {
vector<int> ans;
for (int t = 0; t < i; t++) ans.push_back(id[t]);
for (int t = j; t <= n; t++) ans.push_back(id[t-1]);
return ans;
}
}
}
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... |