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 = 10000;
int a[N] , b[N];
vector<int>g[N];
bool used[21][(1 << 20)];
int n , T , q , m ;
void rec(int v , int x ){
if(v == n ){
cout << "YES";
exit(0);
}
if (used[v][x]) return;
used[v][x] = true;
for(int j:g[a[v]]){
if((x&j)== 0 ){
rec(v + 1 , (x | j));
}
}
}
signed main(){
ios_base::sync_with_stdio(0) , cin.tie(0);
cin>> n >> m ;
for(int i=0 ; i < n ;i++)cin>> a[i];
for(int i=0 ; i < m; i++)cin>> b[i];
for(int i = 0 ; i < (1 << m ); 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);
}
rec(0, 0);
cout << "NO";
}
# | 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... |