# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
900098 | mannshah1211 | Detecting Molecules (IOI16_molecules) | C++14 | 1 ms | 348 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>
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
std::vector<std::pair<int, int>> indices;
for (int i = 0; i < w.size(); i++) {
indices.push_back(std::make_pair(w[i], i));
}
int n = indices.size();
std::vector<int> prefix_sums(n);
for (int i = 0; i < n; i++) {
if (i == 0) {
prefix_sums[i] = indices[i].first;
} else {
prefix_sums[i] = prefix_sums[i - 1] + indices[i].first;
}
}
std::function<int(int, int)> segment_sum = [&](int l, int r) {
if (l == 0) {
return prefix_sums[r];
} else {
return prefix_sums[r] - prefix_sums[l - 1];
}
};
std::sort(indices.begin(), indices.end());
for (int i = 0; i < n; i++) {
int low = i, high = n - 1, index = -1;
while (low <= high) {
int middle = (low + high) / 2;
if (segment_sum(i, middle) >= l) {
index = middle;
high = middle - 1;
} else {
low = middle + 1;
}
}
if (index != -1) {
assert(segment_sum(i, index) >= l);
}
if (index != -1 && segment_sum(i, index) <= u) {
std::vector<int> answer;
for (int j = i; j <= index; j++) {
answer.push_back(indices[j].second);
}
return answer;
}
}
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... |