This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://oj.uz/problem/view/IZhO14_bank
#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
vector <int> A(n), B(m);
for (int& x : A) cin >> x;
for (int& x : B) cin >> x;
vector <vector <int>> mask_set(n);
for (int i = 0; i < n; ++i) {
for (int mask = 0; mask < (1 << m); ++mask) {
int sum = 0;
for (int x = mask; x; x -= x & -x) {
sum += B[__builtin_ctz(x)];
}
if (sum == A[i]) mask_set[i].push_back(mask);
}
}
vector <int> dp(1 << m);
dp[0] = true;
for (int i = 0; i < n; ++i) {
vector <int> new_dp(1 << m);
for (int mask = 0; mask < (1 << m); ++mask) {
if (not dp[mask]) continue;
for (int x : mask_set[i]) {
if ((mask & x)) continue;
new_dp[mask ^ x] = true;
}
}
dp = move(new_dp);
}
cout << (*max_element(dp.begin(), dp.end()) ? "YES\n" : "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... |