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>
#define maxA 1010
#define maxn 21
using namespace std;
int n, m, a[maxn],b[maxn], ans;
vector<vector<int> > allMasks;
int dp[maxn][1<<20];
int main(){
ios_base::sync_with_stdio(0);
cout.tie(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];
}
allMasks.resize(maxA, vector<int>());
for(int i = 0; i < (1<<m); ++i){
int tmp = 0;
for(int j = 0; j < m; ++j){
tmp += ((i>>j) & 1)*b[j];
}
if(tmp < maxA){
allMasks[tmp].push_back(i);
}
}
for(int i = 0; i < n; ++i){
if(i == 0){
for(auto j:allMasks[a[i]]){
dp[i][j] = 1;
}
continue;
}
for(int mask = 0; mask < (1<<m); ++mask){
for(auto x : allMasks[a[i]]){
//cerr << x << ' ';
if(((x & mask) == x) and dp[i-1][mask^x]){
dp[i][mask] = 1;
//cerr << i << ' ' << mask << '\n';
break;
}
}
}
}
for(int i = 0; i < (1<<m); ++i){
ans |=dp[n-1][i];
}
if(ans){
cout<<"YES\n";
} else {
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... |