# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37843 | Just_Solve_The_Problem | Bank (IZhO14_bank) | C++11 | 194 ms | 1784 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;
#define pb push_back
const int N = (int)22;
const int NN = (1 << 20);
int a[N], b[N];
bool used[NN];
int n, m;
vector < int > vec[N];
void go (int pos, int mask) {
if (used[mask]) return ;
used[mask] = 1;
if (pos == n) {
puts("YES");
exit(0);
}
for (int to : vec[pos]) {
if (mask & to) continue;
go(pos + 1, mask | to);
}
}
main () {
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 j = 0; j < m; j++) {
if (mask & (1 << j)) {
sum += b[j];
}
}
for (int j = 0; j < n; j++) {
if (sum == a[j]) {
vec[j].pb(mask);
}
}
}
go(0, 0);
puts("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... |