# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535340 | nicolexxuu | Bank (IZhO14_bank) | C++14 | 61 ms | 45704 KiB |
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 MAXN 21
using namespace std;
int a[MAXN], b[MAXN];
int dp[1 << MAXN];
bool possible[MAXN][1 << MAXN];
vector<int> combos[MAXN * 1000];
int N, M;
int main() {
ios_base::sync_with_stdio(0);
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];
combos[0].push_back(0);
for(int mask = 1; mask < (1 << M); mask++) {
int idx = 0;
// cout << "mask: " << mask << endl;
while(!(mask && (1 << idx))) idx++;
// cout << "idx: " << idx << endl;
dp[mask] = dp[mask - (1 << idx)] + b[idx];
combos[dp[mask]].push_back(mask);
}
possible[0][0] = true;
for(int i = 0; i < N; i++) {
for(int mask = 1; mask < (1 << M); mask++) {
for(int combo : combos[a[i]]) {
if((combo & mask) == combo) possible[i+1][mask] |= possible[i][mask - combo];
}
}
}
bool res = false;
for(int i = 0; i < (1 << M); i++) res |= possible[N][i];
if(res) cout << "YES\n";
else cout << "NO\n";
}
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... |