# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
652550 | chanhchuong123 | Bank (IZhO14_bank) | C++14 | 185 ms | 82508 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>
using namespace std;
#define task "C"
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n, m;
int a[20], b[20];
int dp[20][1 << 20];
vector<int> MASK[20];
bool DP(int i, int mask) {
if (i < 0) {
cout << "YES";
exit(0);
}
if (dp[i][mask] > -1) return dp[i][mask];
int ans = 0;
for (int state: MASK[i]) {
if (state & mask) continue;
ans |= DP(i - 1, mask | state);
}
return dp[i][mask] = ans;
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int j = 0; j < m; j++) cin >> b[j];
if (accumulate(a, a + n, 0) > accumulate(b, b + m, 0)) {
cout << "NO"; exit(0);
}
for (int mask = 0; mask < (1 << m); mask++) {
int sum = 0;
for (int i = 0; i < m; i++)
if (mask >> i & 1) sum += b[i];
for (int i = 0; i < n; i++)
if (sum == a[i]) MASK[i].push_back(mask);
}
memset(dp, -1, sizeof(dp));
DP(n - 1, 0); cout << "NO";
//cout << (DP(n - 1, 0) ? "YES" : "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... |