# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1279579 | ducanh0811 | Bank (IZhO14_bank) | C++20 | 1095 ms | 8596 KiB |
#include <bits/stdc++.h>
#define int long long
#define MASK(i) (1 << (i))
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define REV(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
using namespace std;
int n, m;
#define MAXN 21
int a[MAXN];
int b[MAXN];
int dp[MASK(MAXN - 1)];
bitset<1005> f;
bool possible(int mask, int x) {
f = {};
f[0] = 1;
for (int sub = mask; sub > 0; sub -= sub & -sub){
int bit = __builtin_ctz(sub);
int ok = b[bit + 1];
f = f | (f << ok);
}
return f[x];
}
void solve(){
cin >> n >> m;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, m) cin >> b[i];
dp[0] = 1;
FOR(i, 1, n){
int x = a[i];
int id = i + 1;
FOR(mask, 0, MASK(m) - 1){
if (dp[mask] != i) continue;
for (int sub = mask; sub < MASK(m); sub = (sub + 1) | mask){
if (dp[sub] > i) continue;
int leftmask = sub ^ mask;
if (possible(leftmask, x)){
dp[sub] = id;
}
}
}
}
if (dp[MASK(m) - 1] == n + 1){
cout << "YES";
} else cout << "NO";
}
#define task "test"
int32_t main(){
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
# | 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... |