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 sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 20;
const int NN = (1 << N);
const int PW = 10;
const int oo = 2e9;
const int md = 998244353;
int pref[N], sum[NN], mm, a[N], b[N], n, m;
bool f[N][NN];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
mm = (1 << m);
for (int msk = 1; msk < mm; msk++){
sum[msk] = 0;
for (int j = 0; j < m; j++)
if (msk & (1 << j))
sum[msk] += b[j];
}
pref[0] = 0;
for (int i = 1; i <= n; i++)
pref[i] = pref[i - 1] + a[i - 1];
f[0][0] = 1;
for (int i = 0; i < n; i++)
for (int msk = 0; msk < mm; msk++){
if (!f[i][msk]) continue;
if (i < n - 1 && sum[msk] == pref[i + 1])
f[i + 1][msk] = 1;
for (int j = 0; j < m; j++)
if (!(msk & (1 << j)))
f[i][msk ^ (1 << j)] = 1;
}
bool ok = 0;
for (int msk = 0; msk < mm; msk++)
if (f[n - 1][msk] && sum[msk] == pref[n]) {
ok = 1;
break;
}
cout << (ok ? "YES" : "NO");
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... |