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 <bits/stdc++.h>
#include "molecules.h"
struct weights {
int wt;
int idx;
};
bool cmp(weights a, weights b) {
return (a.wt < b.wt);
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
if(l == u) {
if(l%w[0] == 0 && l/w[0] <= n) { //all weights equal
std::vector<int> ans(l/w[0]);
for(int i = 0; i < l/w[0]; i++)
ans[i] = i;
return ans;
}
else
return std::vector<int>(); //no subarray found
}
int total_weight = 0, i = 0;
std::queue<int> indices;
std::vector<struct weights> wts(n);
for(int i = 0; i < n; i++)
wts[i] = {w[i], i};
std::sort(wts.begin(), wts.end(), cmp);
while(total_weight < l && i < n) {
total_weight += wts[i].wt;
indices.push(wts[i++].idx);
}
i = 0;
while(total_weight > u && i < n) {
total_weight -= wts[i++].wt;
indices.pop();
}
if(total_weight < l || total_weight > u) return std::vector<int>(); //no subarray found
std::vector<int> ans(indices.size());
i = 0;
while(!indices.empty()) {
ans[i++] = indices.front();
indices.pop();
}
return ans;
}
# | 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... |