This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//UNSTOPPABLE
#include "bits/stdc++.h"
using namespace std;
int n,m,a[20],b[20],used[(1 << 20) + 1][21];
set <int> g[1001];
void rec(int mask , int i){
if(used[mask][i]) return;
used[mask][i] = 1;
if(i == n){
cout << "YES\n";
exit(0);
}
for(auto it : g[a[i]]){
if((mask & it) || ((mask | it) == (1 << m) - 1 && i != n - 1)){
continue;
}
rec((mask | it) , i + 1);
}
}
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 mask = 0 ; mask < (1 << m) ; mask++){
int sum = 0;
for(int i = 0 ; i < m ; i++){
if(((mask >> i) & 1)){
sum += b[i];
}
}
if(sum <= 1000){
g[sum].insert(mask);
}
}
rec(0 , 0);
cout << "NO\n";
}
# | 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... |