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>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 20;
bool dp[N+1][1<<N];
int a[N], b[N];
int sum[1<<N];
int n, m;
__attribute__((optimize("O3")))
void gensup(int x, int y, int i, int pos)
{
if (i == m) {
dp[pos+1][y] |= dp[pos][y^x];
return;
}
if ((x & (1<<i)) == 0)
gensup(x, y, i+1, pos);
gensup(x, y ^ (1<<i), i+1, pos);
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m;
Loop (i,0,n)
cin >> a[i];
Loop (i,0,m)
cin >> b[i];
memset(dp[0], 1, sizeof(dp[0]));
Loop (i,1,1<<m)
sum[i] = sum[i ^ (i & -i)] + b[__builtin_ctz(i)];
Loop (i,0,n) {
Loop (j,0,1<<m) {
if (sum[j] == a[i])
gensup(j, 0, 0, i);
}
}
cout << (dp[n][(1<<m)-1]? "YES": "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... |