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>
#include<algorithm>
using namespace std;
int n, m;
vector<int> a, b, s;
int main() {
{ // input
cin >> n >> m;
a.resize(n), b.resize(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
}
{ // mask sum
s.resize(1 << m, 0);
for (int c = 0; c < (1 << m); c++) {
for (int i = 0; i < m; i++) {
if (c&(1 << i)) s[c] += b[i];
}
// cout << c << ' ' << s[c] << endl;
}
}
{ // main
sort(a.begin(), a.end());
vector<int> valid;
for (int c = 0; c < (1 << m); c++) {
if (s[c] == a[0]) valid.push_back(c);
}
for (int i = 1; i < n; i++) {
vector<int> new_valid;
for (int c = 0; c < (1 << m); c++) {
if (s[c] != a[i]) continue;
for (int c_prv : valid) {
if ((c_prv | c) == c_prv + c) new_valid.push_back(c_prv + c);
}
}
valid = new_valid;
}
cout << (valid.empty() ? "NO" : "YES") << '\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... |