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 <iostream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;
typedef vector<bool> VI;
typedef vector<VI> VVI;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
const int N = w.size();
// assert(N <= 100 && u <= 1000);
VVI can(N+1, VI(u+1));
VVI P(N+1, VI(u+1));
can[0][0] = true;
for (int n = 0; n < N; ++n) {
for (int sum = 0; sum <= u; ++sum) {
if ( can[n][sum] ) {
can[n+1][sum] = true;
P[n+1][sum] = false;
if (sum + w[n] <= u) {
can[n+1][sum + w[n]] = true;
P[n+1][sum + w[n]] = true;
}
}
}
}
for (int sum = l; sum <= u; ++sum) {
if (can[N][sum]) {
vector<int> res;
for (int n = N, s = sum; s != 0; ) {
if (P[n][s]) {
res.push_back(n-1);
s -= w[n-1];
--n;
}
else {
--n;
}
}
return res;
}
}
return {};
}
# | 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... |