# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
640101 | bonk | Bank (IZhO14_bank) | C++14 | 845 ms | 90324 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(21), b(21);
vector<int>bit(21);
int dp[20][(1<<20) + 1];
int n, m;
bool f(int idx, int mask){
if(idx >= n) return 1;
auto &cur = dp[idx][mask];
if(cur != -1) return cur;
cur = 0;
for(int i = 0; i < v[a[idx]].size(); i++){
if(!(mask & v[a[idx]][i])) cur |= f(idx + 1, mask | v[a[idx]][i]);
}
return cur;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> 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(f(0, 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... |