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 f0(i, n) for(int i=(0); i<n; i++)
#define f1(i, n) for(int i=(1); i<=n; i++)
#define bit(x, y) (((x) >> (y))&1)
using namespace std;
typedef long long ll;
const int N = 22;
int n, m, a[N], b[N];
int f[22][1 << 20];
vector <int> t[N];
int calc(int i, int s){
if(f[i][s] >= 0) return f[i][s];
if(i == n + 1){
cout << "YES";
exit(0);
}
int &ans = f[i][s];
ans = 0;
for(auto x:t[i]){
if(x & s) continue;
ans = ans | calc(i + 1, s | x);
if(ans) break;
}
return ans;
}
main(){
ios_base::sync_with_stdio(0);
cin >> n >> m;
f1(i, n) cin >> a[i];
f1(i, m) cin >> b[i];
memset(f, -1, sizeof(f));
for(int i = 1; i <= (1 << m); i++){
int val = 0;
int save = 0;
f0(j, m){
if(bit(i, j)) val += b[j + 1];
if(bit(i, j)){
save = save + (1 << j);
}
}
f1(j, n){
if(val==a[j]) t[j].push_back(save);
}
}
calc(1, 0);
cout << "NO";
}
Compilation message (stderr)
bank.cpp:30:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | 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... |