# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388335 | Qw3rTy | Bank (IZhO14_bank) | C++11 | 91 ms | 8532 KiB |
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 pi pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxN = 20+2;
void testIO(){
freopen("../test.in","r",stdin);
return;
}
pi f[(1<<maxN)];
int a[maxN]; int b[maxN];
int N,M;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//testIO();
cin >> N >> M;
for(int i = 1; i <= N; ++i)cin >> a[i]; a[N+1] = 0;
for(int i = 1; i <= M; ++i)cin >> b[i];
f[0].fi = 1; f[0].se = a[1];
for(int i = 0; i < (1<<M); ++i){
for(int j = 1; j <= M; ++j){
if((i&(1<<(j-1))) != 0)continue; //banknote j is already used
if(b[j] > f[i].se)continue; //the banknote is too large
if(b[j] == f[i].se){ //刚刚好
f[i|(1<<(j-1))].fi = f[i].fi + 1;
if(f[i|(1<<(j-1))].fi == (N+1)){
cout << "YES" << '\n';
return 0;
}
f[i|(1<<(j-1))].se = a[f[i].fi+1];
}
else{
f[i|(1<<(j-1))].fi = f[i].fi;
f[i|(1<<(j-1))].se = f[i].se - b[j];
}
}
}
cout << "NO" << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |