#include "molecules.h"
#include <bits/stdc++.h>
#define debug printf
#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ll long long
#define sz size()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define tiii tuple<int,int,int>
#define mkt make_tuple
const int MAX = 10010 ;
using namespace std ;
bool dp[MAX] ;
vector<int> res , aux[MAX] ;
bool find(int idx, int num )
{
int l = 0 , r = (int)(aux[idx].sz) - 1 , mid ;
while(l<=r)
{
mid = (l+r)>>1 ;
if( aux[idx][mid] < num )
l = mid + 1 ;
else if( aux[idx][mid] > num )
r = mid - 1 ;
else return true ;
}
return aux[idx][mid] == num ;
}
vector<int> find_subset(int l, int u, vector<int> w)
{
int cnt = 1 ;
dp[0] = true ;
for(int i : w)
{
for(int j = u ; j >= 0 ; j-- )
{
if(!dp[j]) continue ;
if( j + i <= u && !dp[j+i] )
{
dp[j+i]=true ;
aux[cnt].pb(j+i) ;
}
}
cnt ++ ;
}
cnt -- ;
lp(i,1,cnt+1) reverse(all(aux[i])) ;
int ok = -1 ;
lp(i,l,u+1)
if( dp[i] ) ok = i ;
if( ok == -1 ) return res ;
for(int i = cnt ; i > 0 ; i-- )
if( w[i-1] <= ok && find(i,ok) )
{
res.pb(i-1) ;
ok -= w[i-1] ;
}
sort(all(res));
return res ;
}
Compilation message
molecules.cpp: In function 'bool find(int, int)':
molecules.cpp:27:43: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
int l = 0 , r = (int)(aux[idx].sz) - 1 , mid ;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
504 KB |
OK (n = 2, answer = YES) |
5 |
Runtime error |
3 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
504 KB |
OK (n = 2, answer = YES) |
5 |
Runtime error |
3 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
504 KB |
OK (n = 2, answer = YES) |
5 |
Runtime error |
3 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
504 KB |
OK (n = 2, answer = YES) |
5 |
Runtime error |
3 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
632 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
504 KB |
OK (n = 2, answer = YES) |
5 |
Runtime error |
3 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |