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;
typedef long long ll;
int n, m, a[20], b[20];
vector<int> masks[20001];
set<int> masks1, masks2;
void search1(int i, int cur_mask)
{
if (i == n / 2)
{
masks1.insert(cur_mask);
return;
}
for (const int &mask : masks[a[i]])
if ((cur_mask & mask) == 0)
search1(i + 1, cur_mask | mask);
}
void search2(int i, int cur_mask)
{
if (i == n)
{
masks2.insert(cur_mask);
return;
}
for (const int &mask : masks[a[i]])
if ((cur_mask & mask) == 0)
search2(i + 1, cur_mask | mask);
}
int dp[2][1 << 20] = {0};
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
for (int mask = 0; mask < (1 << m); mask++)
{
int sum = 0;
for (int i = 0; i < m; i++)
if (mask & (1 << i))
sum += b[i];
masks[sum].push_back(mask);
}
search1(0, 0);
search2(n / 2, 0);
for (int mask : masks1)
dp[0][mask]++;
for (int mask : masks2)
dp[1][mask]++;
for (int i = 0; i < m; i++)
for (int j = 0; j < (1 << m); j++)
if (!(j & (1 << i)))
{
dp[0][j] += dp[0][j | (1 << i)];
dp[1][j] += dp[1][j | (1 << i)];
}
int ans = 0;
for (int i = 0; i < (1 << m); i++)
if (__builtin_popcount(i) % 2)
ans -= dp[0][i] * dp[1][i];
else
ans += dp[0][i] * dp[1][i];
cout << (ans == 0 ? "NO\n" : "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... |