#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;
bitset<10004> dp[10004],vis[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;
bool x = solve(0,0);
return res;
}
// comment out pls
/*
int main(){
vector<int> vv = {6,8,8,7};
vector<int> v = find_subset(15,17,vv);
for(auto i:v)cout<<i<<" ";
cout<<endl;
return 0;
}
*/
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:29:7: warning: unused variable 'x' [-Wunused-variable]
29 | bool x = solve(0,0);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
0 ms |
384 KB |
OK (n = 12, answer = YES) |
3 |
Correct |
0 ms |
384 KB |
OK (n = 12, answer = NO) |
4 |
Correct |
1 ms |
384 KB |
OK (n = 12, answer = NO) |
5 |
Correct |
1 ms |
384 KB |
OK (n = 12, answer = YES) |
6 |
Incorrect |
0 ms |
384 KB |
Contestant can not find answer, jury can |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |