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"
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vector <int> ret;
int n = w.size();
vector <pii> W(n);
for(int i = 0; i < n; ++i) {
W[i] = {w[i], i};
}
const int MAXN = 5e5+1;
vector <bitset <MAXN>> dp(n+1);
dp[0][0] = true;
for(int i = 1; i <= n; ++i) {
for(int j = 0; j < MAXN; ++j) {
dp[i][j] = dp[i][j] || dp[i-1][j];
if (W[i-1].first <= j) dp[i][j] = dp[i][j] || dp[i-1][j-W[i-1].first];
}
}
for(int i = l; i <= u; ++i) {
int target = i;
if (dp[n][target] == false) continue;
vector <int> tmp;
for(int j = n; j > 0; --j) {
if (dp[j-1][target]) continue;
tmp.push_back(W[j-1].second);
target -= W[j-1].first;
}
if (target == 0) {
ret = tmp;
break;
}
}
return ret;
}
# | 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... |