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() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
for (int i = 0; i < m; ++i) {
std::cin >> b[i];
}
for (int i = 1; i < n; ++i) {
a[i] += a[i - 1];
}
std::map<int, std::vector<int>> s;
for (int x : a) {
s[x] = {};
}
std::vector<int> dp(1 << m, 0);
for (int i = 0; i < (1 << m); ++i) {
for (int j = 0; j < m; ++j) {
if (i & (1 << j)) {
dp[i] = dp[i ^ (1 << j)] + b[j];
}
}
if (s.count(dp[i])) {
s[dp[i]].push_back(i);
}
}
std::vector<int> u, v;
u = {0};
for (auto &[_, y] : s) {
for (int x : u) {
for (int z : y) {
if (x & (~z))
continue;
v.push_back(z);
}
}
u = v;
v = {};
}
if (u.size()) {
std::cout << "YES\n";
}
else {
std::cout << "NO\n";
}
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... |