# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088201 | T0p_ | Bank (IZhO14_bank) | C++14 | 178 ms | 182096 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 = 20;
int a[N], b[N], dp[N][1<<N];
vector<int> sum_to_bit[20001];
int solve(int n, int s) {
if (dp[n][s] != -1) {
return dp[n][s];
}
if (n == 0) {
return dp[n][s] = 1;
}
int res = 0;
for (int bit : sum_to_bit[a[n-1]]) {
if ((bit & s) == bit) {
res |= solve(n-1, bit ^ s);
}
}
return dp[n][s] = res;
}
int main() {
int n, m;
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 i=0 ; i<1<<m ; i++) {
int sum = 0;
for (int j=0 ; j<m ; j++) {
if (i & (1<<j)) {
sum += b[j];
}
}
sum_to_bit[sum].push_back(i);
}
memset(dp, -1, sizeof(dp));
printf(solve(n, (1<<m)-1) == 1 ? "YES\n" : "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... |