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>
int main(void) {
std::ios_base::sync_with_stdio(0);
std::cin.tie(nullptr);
int n, m; std::cin >> n >> m;
std::vector <int> a(n), b(m);
for (int& ai : a)
std::cin >> ai;
for (int& bi : b)
std::cin >> bi;
std::vector <std::vector <int>> mask(n);
for (int x = 0; x < (1 << m); x += 1) {
int sum = 0;
for (int i = 0; i < m; i += 1)
sum += ((x >> i) & 1) * b[i];
for (int i = 0; i < n; i += 1) if (a[i] == sum)
mask[i].push_back(x);
}
std::vector <std::vector <int>> dp(n + 1, std::vector <int> (1 << m));
dp[0][0] = 1;
for (int i = 0; i < n; i += 1) for (int x = 0; x < (1 << m); x += 1) if (dp[i][x] == 1) {
for (int y : mask[i]) if ((x & y) == 0)
dp[i + 1][x | y] = 1;
}
std::cout << (*std::max_element(dp[n].begin(), dp[n].end()) ? "YES" : "NO");
return 0^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... |