# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37763 | Just_Solve_The_Problem | Bank (IZhO14_bank) | C++11 | 480 ms | 1636 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 = (int)22;
const int NN = (1 << 20);
int a[N], b[N];
bool dp[NN];
bool used[NN];
int n, m;
void go (int mask, vector < int > vec) {
bool fl = 1;
if (used[mask]) return ;
used[mask] = 1;
for (int i = 0; i < n; i++) {
if (vec[i] != 0) fl = 0;
}
if (fl) {
// cout << mask << endl;
puts("YES");
exit(0);
}
for (int i = 0; i < n; i++) {
if (vec[i] == 0) continue;
for (int j = 0; j < m; j++) {
if (vec[i] >= b[j] && !(mask & (1 << j))) {
vec[i] -= b[j];
go(mask | (1 << j), vec);
vec[i] += b[j];
}
}
}
}
main () {
scanf ("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf ("%d", a + i);
}
sort(a, a + n);
for (int i = 0; i < m; i++) {
scanf ("%d", b + i);
}
sort(b, b + m);
vector < int > vec(n);
for (int i = 0; i < n; i++) {
vec[i] = a[i];
}
go(0, vec);
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... |