# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321041 | tushar_2658 | Bank (IZhO14_bank) | C++14 | 534 ms | 15588 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 maxn = 21;
bool dp[maxn][1 << maxn];
int a[maxn], b[maxn];
int n, m;
vector<int> make[maxn];
int main(int argc, char const *argv[])
{
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
for(int i = 0; i < m; ++i){
scanf("%d", &b[i]);
}
for(int mask = 0; mask < (1 << m); ++mask){
int sum = 0;
for(int i = 0; i < m; ++i){
if((mask >> i) & 1){
sum += b[i];
}
}
for(int i = 0; i < n; ++i){
if(a[i] == sum){
make[i].push_back(mask);
}
}
}
for(int i = 0; i < n; ++i){
for(int mask = 0; mask < (1 << m); ++mask){
if((mask == 0 && i == 0) || (i > 0 && dp[i - 1][mask])){}
else continue;
for(auto nmask : make[i]){
if((nmask & mask) == 0){
dp[i][(nmask ^ mask)] = 1;
}
}
}
}
bool good = 0;
for(int i = 0; i < (1 << m); ++i){
if(dp[n - 1][i]){
good = 1;
break;
}
}
good ? cout << "YES" << '\n' : 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... |