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 <iostream>
#include <vector>
using namespace std;
#define sz(s) (int)(s.size())
#define eb emplace_back
const int N = 2e5 + 5;
vector <int> v[N];
bool u[20][1 << 20];
int a[N], b[N];
void rec(int pos, int state, int n) {
if (pos == n) {
cout << "YES";
exit(0);
}
if (u[pos][state])
return;
u[pos][state] = true;
for (auto to : v[pos]) {
if (state & to)
continue;
rec(pos + 1, state | to, n);
}
}
int main () {
cerr << "Ready\n";
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++ i)
cin >> a[i];
for (int i = 0; i < m; ++ i)
cin >> b[i];
for (int state = 0; state < (1 << m); ++ state) {
int sum = 0;
for (int i = 0; i < m; ++ i)
if (state & (1 << i))
sum += b[i];
for (int i = 0; i < n; ++ i)
if (sum == a[i])
v[i].eb(state);
}
rec(0, 0, n);
cout << "NO";
return 0;
}
# | 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... |