# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
933299 | SmuggingSpun | Bank (IZhO14_bank) | C++14 | 31 ms | 8736 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 taskname "bank"
using namespace std;
const int lim = 20;
int a[lim], b[lim], cnt[1 << lim], remain[1 << lim];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".in", "r")){
freopen(taskname".in", "r", stdin);
}
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
memset(cnt, -1, sizeof(cnt));
remain[0] = a[cnt[0] = 0];
for(int mask = 1; mask < (1 << m); mask++){
int state = mask;
while(state > 0){
int x = __builtin_ctz(state), index = cnt[mask ^ (1 << x)], left = remain[mask ^ (1 << x)];
if(index == -1 || b[x] > left){
state ^= 1 << x;
continue;
}
if(b[x] == left){
if(index == n - 1){
return cout << "YES", 0;
}
remain[mask] = a[cnt[mask] = ++index];
}
else{
remain[mask] = left - b[x];
cnt[mask] = index;
}
break;
}
}
cout << "NO";
}
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... |