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;
void testCase() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1), b(m);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int &x : b) {
cin >> x;
}
vector<vector<int>> states(n + 1);
for (int mask = 1; mask < (1 << m); ++mask) {
int sum = 0;
for (int i = 0; (1 << i) <= mask; ++i) {
if (mask & (1 << i)) {
sum += b[i];
}
}
for (int i = 1; i <= n; ++i) {
if (a[i] == sum) {
states[i].emplace_back(mask);
}
}
}
vector<vector<bool>> can(n + 1, vector<bool>(1 << m));
can[0][0] = true;
for (int i = 1; i <= n; ++i) {
for (int mask = 0; mask < (1 << m); ++mask) {
if (can[i - 1][mask]) {
for (int x : states[i]) {
if ((mask & x) == 0) {
can[i][mask | x] = true;
}
}
}
}
}
if (count(can[n].begin(), can[n].end(), true)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
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... |