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 <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]){
bool ok = 1;
for(auto y:x){
if(bit(s, y)) ok = 0;
}
if(ok){
int r = s;
for(auto y:x){
r = r + (1 << y);
}
ans = ans | calc(i + 1, r);
if(ans) return ans;
}
}
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;
vector <int> save;
f0(j, m){
if(bit(i, j)) val += b[j + 1];
if(bit(i, j)){
save.push_back(j);
}
}
f1(j, n){
if(val==a[j]) t[j].push_back(save);
}
}
calc(1, 0);
cout << "NO";
}
Compilation message (stderr)
bank.cpp:39: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... |