# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
945994 | iaraha | Bank (IZhO14_bank) | C++14 | 275 ms | 36596 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.
// Эксперт до 15.04.2024 Насиб
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pf push_front
#define pof pop_front
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define Yes cout << "YES \n"
#define No cout << "NO \n"
#define Ferarri ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//////////////////// the code below ////////////////////
bool dp[(1 << 21) + 5][25] = {};
int mp[(1 << 21) + 5] = {};
signed main(){
Ferarri
int n, m;
cin >> n >> m;
int a[n], b[m];
vector<int>w[n + 5];
vector<int> can[n + 5];
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 < (1 << m); i++) {
int s = 0;
for (int j = 0; j < m; j++) {
if (i & (1 << (m - j - 1))) {
s += b[j];
}
}
mp[i] = s;
}
bool chk = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (mp[j] == a[i]) {
w[i].pb(j);
if (i == 0) {
can[0].push_back(j);
dp[j][i] = 1;
if (n == 1) chk = 1;
}
}
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < w[i].size(); j++) {
for (int k = 0; k < can[i - 1].size(); k++) {
if (!(w[i][j] & can[i - 1][k]) && !dp[w[i][j] + can[i - 1][k]][i]) {
dp[w[i][j] + can[i - 1][k]][i] = 1;
can[i].push_back(w[i][j] + can[i - 1][k]);
if (i == n - 1)
chk = 1;
}
}
}
}
if (chk) Yes;
else No;
}
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... |