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;
#define sz(x) (int)x.size()
vector<int> a;
int low,high;
vector<int> res;
bool dp[10004][10004],vis[10004][10004];
bool solve(int index,int sum){
if(index >= sz(a))return 0;
if(sum <= high && sum >= low)return 1;
if(vis[index][sum]){
if(dp[index][sum])
res.push_back(index);
return dp[index][sum];
}
vis[index][sum] = 1;
bool ans = solve(index+1,sum+a[index]);
if(ans){
res.push_back(index);
return 1;
}
return solve(index+1,sum);
}
vector<int> find_subset(int l, int u, vector<int> w) {
a = w;
low = l,high = u;
res.clear();
memset(vis,0,sizeof(vis));
memset(dp,0,sizeof(dp));
bool x = solve(0,0);
return res;
}
/*
// comment out pls
int main(){
vector<int> vv = {1,2,3};
vector<int> v = find_subset(0,11,vv);
for(auto i:v)cout<<i<<" ";
cout<<endl;
return 0;
}
*/
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:32:7: warning: unused variable 'x' [-Wunused-variable]
32 | bool x = solve(0,0);
| ^| # | 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... |