This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize ("Ofast")
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define mp make_pair
#define pb push_back
map<pair<int, pair<int, int>>, bool> dp;
vi sb;
bool findSubset(int x, int l, int r, vector<int> &w) {
if (l <= 0) return 1;
if (x == 0) {
if (l <= w[x] && w[x] <= r) {
sb.pb(x);
return 1;
}
return 0;
}
auto it = dp.find(mp(x, mp(l, r)));
if (it != dp.end()) return it->second;
bool found = 0;
if (findSubset(x-1, l, r, w)) {
found = 1;
}
if (!found && w[x] <= r && findSubset(x-1, l-w[x], r-w[x], w)) {
sb.pb(x);
found = 1;
}
return dp[mp(x, mp(l, r))] = found;
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
findSubset(n-1, l, u, w);
return sb;
}
# | 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... |