#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define F first
#define S second
#define pb push_back
#define sz(x) (ll)x.size()
typedef vector <ll> vi;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
#define N 100
#define MAX_SUM 100000
ll dp[N+1][MAX_SUM+1];
vi w;
vi ans;
ll l, r;
bool foundAns = false;
void tabb(ll n) {
for (ll i =0; i<n; i++) cout<<"\t";
}
bool solve(ll n, ll s, ll tab = 0){
// tabb(tab);
// dbg2(n,s);
if (foundAns){
// dbg(1);
return false;
}
if (n >= sz(w)){
// dbg(2);
bool foundAns = (l <= s && s <= r);
// dbg3(n,s,foundAns)
return foundAns;
}
if (s > r)return false;
if (dp[n][s] != -1) return dp[n][r];
bool ans1 = solve(n+1, s+w[n], tab+1);
if (ans1){
ans.pb(n);
return dp[n][r] = ans1;
}
bool ans2 = solve(n+1, s, tab+1);
return dp[n][r] = (ans1 || ans2);
}
vi find_subset(int L, int R, vi c) {
w = c;
l = L, r = R;
for (ll i =0; i<=N; i++){
for (ll j = 0; j<=MAX_SUM; j++){
dp[i][j] = -1;
}
}
solve(0, 0);
return ans;
}
/*
4 15 17
6 8 8 7
*/
Compilation message
molecules.cpp: In function 'bool solve(int, int, int)':
molecules.cpp:58:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
58 | return dp[n][r] = ans1;
| ~~~~~~~~~^~~~~~
molecules.cpp:63:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
63 | return dp[n][r] = (ans1 || ans2);
| ~~~~~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39772 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
18 ms |
39772 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
15 ms |
39768 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
16 ms |
39772 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
16 ms |
39904 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
20 ms |
39772 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
14 ms |
39952 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
14 ms |
39828 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
13 ms |
39772 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
15 ms |
39860 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
15 ms |
39768 KB |
OK (n = 3, answer = NO) |
18 |
Execution timed out |
1037 ms |
40024 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
39768 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
13 ms |
39772 KB |
OK (n = 12, answer = YES) |
3 |
Correct |
15 ms |
39856 KB |
OK (n = 12, answer = NO) |
4 |
Correct |
16 ms |
39768 KB |
OK (n = 12, answer = NO) |
5 |
Correct |
15 ms |
39796 KB |
OK (n = 12, answer = YES) |
6 |
Correct |
16 ms |
39780 KB |
OK (n = 12, answer = YES) |
7 |
Correct |
17 ms |
39772 KB |
OK (n = 12, answer = YES) |
8 |
Correct |
22 ms |
39788 KB |
OK (n = 12, answer = YES) |
9 |
Correct |
16 ms |
39876 KB |
OK (n = 6, answer = YES) |
10 |
Correct |
20 ms |
39772 KB |
OK (n = 12, answer = YES) |
11 |
Execution timed out |
1081 ms |
39768 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39772 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
18 ms |
39772 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
15 ms |
39768 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
16 ms |
39772 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
16 ms |
39904 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
20 ms |
39772 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
14 ms |
39952 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
14 ms |
39828 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
13 ms |
39772 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
15 ms |
39860 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
15 ms |
39768 KB |
OK (n = 3, answer = NO) |
18 |
Execution timed out |
1037 ms |
40024 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39772 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
18 ms |
39772 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
15 ms |
39768 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
16 ms |
39772 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
16 ms |
39904 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
20 ms |
39772 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
14 ms |
39952 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
14 ms |
39828 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
13 ms |
39772 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
15 ms |
39860 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
15 ms |
39768 KB |
OK (n = 3, answer = NO) |
18 |
Execution timed out |
1037 ms |
40024 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39772 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
18 ms |
39772 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
15 ms |
39768 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
16 ms |
39772 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
16 ms |
39904 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
20 ms |
39772 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
14 ms |
39952 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
14 ms |
39828 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
13 ms |
39772 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
15 ms |
39860 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
15 ms |
39768 KB |
OK (n = 3, answer = NO) |
18 |
Execution timed out |
1037 ms |
40024 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39772 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
18 ms |
39772 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
15 ms |
39768 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
16 ms |
39772 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
16 ms |
39904 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
20 ms |
39772 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
14 ms |
39952 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
14 ms |
39828 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
13 ms |
39772 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
15 ms |
39860 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
15 ms |
39772 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
18 ms |
39772 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
16 ms |
39772 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
15 ms |
39768 KB |
OK (n = 3, answer = NO) |
18 |
Execution timed out |
1037 ms |
40024 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |