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 ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 20;
const ll oo = 1e15 + 69;
int n, m, a[maxn], b[maxn];
pa dp[2][1 << maxn];
bool getbit(const int mask, int i) {
return ((mask >> i) & 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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 i = 0; i < 2; i++)
for(int mask = 0; mask < (1 << m); mask++) dp[i][mask] = make_pair(-1, 0);
dp[0][(1 << m) - 1] = {0, 0};
for(int i = 0; i < n; i++)
for(int mask = (1 << m) - 1; mask; mask--) {
if(dp[i & 1][mask].fi == i)
for(int x = mask; x; x -= x&-x) {
int j = __builtin_ctz(x), s = dp[i & 1][mask].se + b[j], add = (s == a[i]);
dp[i & 1 ^ add][mask ^ (1 << j)] = {i + add, (add == 0 ? s:0)};
if(i + add == n) {
cout<<"YES";
exit(0);
}
}
dp[i & 1][mask] = {-1, 0};
}
cout<<"NO";
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:45:26: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
45 | dp[i & 1 ^ add][mask ^ (1 << j)] = {i + add, (add == 0 ? s: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... |