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;
vector<int> find_subset(int l, int u, std::vector<int> w) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n = w.size();
vector <int> dp(u+1, 1e9);
dp[0] = -1;
set <int> filled, not_filled;
filled.insert(0);
for (int i = 1; i <= u; i++)
not_filled.insert(i);
for (int i = 0; i < n; i++) {
if (not_filled.empty())
break;
if (not_filled.size() < filled.size()) {
vector <int> to_shift;
for (auto k = --not_filled.end(); ; k--) {
int j = *k;
if (j >= w[i] && dp[j - w[i]] != 1e9) {
to_shift.push_back(j);
dp[j] = i;
}
if (k == not_filled.begin())
break;
}
for (auto j : to_shift) {
not_filled.erase(j);
filled.insert(j);
}
} else {
vector <int> to_shift;
for (auto k = --filled.end(); ; k--) {
int j = *k;
if (j + w[i] <= u && dp[j + w[i]] == 1e9) {
to_shift.push_back(j + w[i]);
dp[j + w[i]] = i;
}
if (k == filled.begin())
break;
}
for (auto j : to_shift) {
not_filled.erase(j);
filled.insert(j);
}
}
}
int st = -1;
vector <int> ans;
for (int i = l; i <= u; i++) {
if (dp[i] != 1e9) {
st = i;
break;
}
}
if (st == -1)
return ans;
while (st > 0) {
int nxt = dp[st];
ans.push_back(nxt);
st = st - w[nxt];
}
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... |