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
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<int>a(n),b(m);
for(int i = 0; i < n; i ++) {
cin >> a[i];
}
for(int i = 0; i < m; i ++) cin >> b[i];
vector<int> g[n];
for(int mask = 0; mask < (1 << m); mask ++) {
int sum = 0;
for(int i = 0; i < m; i ++) {
if(mask & (1 << i)) sum += b[i];
}
for(int i = 0; i < n; i ++) {
if(sum == a[i]) g[i].push_back(mask);
}
}
vector <vector <int>> dp(n+1, vector <int> (1 << m, 0));
dp[0][0]=1;
for(int i = 0; i < n; i ++) {
for(int mask = 0; mask < (1 << m); mask ++) {
if(dp[i][mask]) {
for(auto j : g[i]) {
if(mask & j) continue;
dp[i+1][mask^j]=1;
}
}
}
}
if(count(dp[n].begin(),dp[n].end(),1)) cout << "YES";
else cout << "NO";
return 0;
}
# | 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... |