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;
using idata = vector<int>;
using igrid = vector<idata>;
const int MAX_N = 20;
const int MAX_M = 20;
const int MAX_MASK = 1 << MAX_M;
int dp[MAX_MASK];
idata salary;
igrid transitions;
int main () {
int N, M; cin >> N >> M;
salary.resize(N);
transitions.resize(N);
for (int iN = 0; iN < N; iN ++) {
int x;
cin >> x;
salary[iN] = x;
}
for (int iM = 0; iM < M; iM ++) {
int x;
cin >> x;
for (int mask = 0; mask < (1 << iM); mask ++)
dp[mask + (1 << iM)] = dp[mask] + x;
}
for (int mask = 0; mask < (1 << M); mask ++) {
for (int i = 0; i < N; i ++) {
if (dp[mask] != salary[i]) continue ;
transitions[i].push_back(mask);
}
}
unordered_set<int> mask_array; mask_array.insert(0);
for (int i = 0; i < N; i ++) {
unordered_set<int> next_mask_array;
for (int mask : mask_array) {
for (int next : transitions[i]) {
if (next & mask) continue ;
next_mask_array.insert(next | mask);
}
}
mask_array = next_mask_array;
}
if (mask_array.size() != 0) cout << "YES\n";
else cout << "NO\n";
}
# | 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... |