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 <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using i64 = long long;
int z=4, n, m, a[21], b[20], dp[1<<20][2];
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")
int main()
{
ShinLena;
cin >> n >> m;
memset(dp, 0x86, sizeof dp);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
dp[0][0] = 0;
for (int j = 0; z && j < (1 << m); ++j)
{
for (int k = 0; k < m; ++k)
{
if (j & (1 << k))
{
int p = j&~(1<<k);
if (dp[p][0] >= 0)
{
dp[j][0] = dp[p][0] + b[k];
break;
}
}
}
}
for (int i = 1, I = 1; z && i <= n; ++i, I^=1)
{
for (int j = 0; z && j < (1 << m); ++j)
{
dp[j][I] = (dp[j][I^1] == a[i]) ? 0 : -1e9;
for (int k = 0; k < m; ++k)
{
if (j & (1 << k))
{
int p = j&~(1<<k);
if (dp[p][I] >= 0)
{
dp[j][I] = dp[p][I] + b[k];
break;
}
}
}
}
}
for (int j = 0; z && j < (1 << m); ++j) if (!dp[j][n&1]) z = 0;
cout << &"YES\0NO"[z];
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... |