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 <bits/stdc++.h>
using namespace std;
#define int long long
#define nn "\n";
#define pb push_back
#define all(v) (v).begin() , (v).end()
const int N = 2e3+ 4;
int a[N] , b[N];
vector<int>g[N];
bool used[21][(1 << 20)];
int n , T , q , m ;
void dfs(int v , int x ){
if(v == n ){
cout << "YES";
exit(0);
}
if (used[v][x]) return;
used[v][x] = true;
for(auto at:g[v+1]){
if((x&at)== 0 ){
dfs(v + 1 , (x | at));
}
}
}
signed main(){
ios_base::sync_with_stdio(0) , cin.tie(0);
cin>> n >> m ;
for(int i=1 ; i <= n ;i++)cin>> a[i];
for(int i=0 ; i < m; i++)cin>> b[i];
for(int i = 0 ; i < (1 << m ) - 1; i++){
int sum =0 ;
for(int j =0 ; j < m; j++){
if(( i >> j )&1 ){
sum+=b[j];
}
}
if(sum <= 1000)g[sum].pb(i);
}
for(int i=0 ; i < g[1].size() ; i++){
dfs(1 , g[1][i]);
}
cout << "NO";
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:39:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0 ; i < g[1].size() ; i++){
| ~~^~~~~~~~~~~~~
# | 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... |