# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
637234 | bonk | Bank (IZhO14_bank) | C++14 | 1095 ms | 8260 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>
using namespace std;
const int N = 20002;
vector<int>v[N];
vector<int>a, b;
vector<int>bit(21);
bool tmp = false;
int n, m;
bool check(int idx){
if(idx >= n || tmp) return true;
for(int i = 0; i < v[a[idx]].size(); i++){
bool ok = true;
for(int j = 0; j < 21; j++){
if((v[a[idx]][i]>>j)&1){
if(bit[j]) ok = false;
bit[j]++;
}
}
if(ok) tmp |= check(idx + 1);
for(int j = 0; j < 21; j++){
if((v[a[idx]][i]>>j)&1) bit[j]--;
}
}
return tmp;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
a.resize(n); b.resize(m);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
int all = (1<<m);
for(int mask = 1; mask < all; mask++){
int sum = 0;
for(int i = 0; i < m; i++){
if((mask>>i)&1) sum += b[i];
}
v[sum].push_back(mask);
}
if(check(0)) cout << "YES" << '\n';
else 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... |