# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
651835 | alvinpiter | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 316 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) {
vector<pair<int, int> > indexedWeights;
for (int i = 0; i < w.size(); i++) {
indexedWeights.push_back({w[i], i});
}
sort(indexedWeights.begin(), indexedWeights.end());
vector<int> result;
// Check if the lightest molecule is larger than u
if (indexedWeights[0].first > u) {
return result;
}
// Check if there is a molecule with weight between l and u
for (auto [weight, index]: indexedWeights) {
if (weight >= l && weight <= u) {
result.push_back(index);
return result;
}
}
// All molecules has weight < l
long long int totalWeight = 0;
for (int i = indexedWeights.size() - 1; i >= 0; i--) {
auto [weight, index] = indexedWeights[i];
totalWeight += weight;
result.push_back(index);
if (totalWeight >= l && totalWeight <= u) {
return result;
}
if (totalWeight > u) {
result.clear();
return result;
}
int lo = 0, hi = i - 1, mid;
while (hi >= lo) {
mid = (lo + hi)/2;
if (totalWeight + indexedWeights[mid].first < l) {
lo = mid + 1;
} else {
hi = mid - 1;
}
}
if (lo < i) {
if (totalWeight + indexedWeights[lo].first <= u) {
result.push_back(indexedWeights[lo].second);
return result;
}
}
}
result.clear();
return result;
}
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... |