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;
#define int long long
#define MAX 21
int a[MAX], b[MAX];
vector<int> sum[MAX * 1000];
bool f[MAX][1 << MAX], flag;
void dfs(int i, int mask, int &n)
{
if (i == n)
{
flag = true;
return;
}
f[i][mask] = true;
for (int other : sum[a[i + 1]])
if ((mask & other) == 0 && !f[i + 1][other])
dfs(i + 1, mask | other, n);
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int s, mask = 0; mask < (1 << m); mask++)
{
s = 0;
for (int j, cur = mask; cur; cur ^= -cur & cur)
{
j = __builtin_ctz(cur);
s += b[j];
}
sum[s].push_back(mask);
}
dfs(0, 0, n);
cout << (flag ? "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... |