# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
763368 | Blagoj | Bank (IZhO14_bank) | C++17 | 1092 ms | 5264 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 endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
int n, m;
vector<int> s, v;
int dp[21][1 << 21];
int solve(int p, int mask) {
if (p == n) return dp[p][mask] = 1;
if (mask == (1 << v.size()) - 1) return dp[p][mask] = -1;
if (dp[p][mask] != 0) return dp[p][mask];
vector<int> c;
for (int i = 0; i < m; i++) if (!(mask & (1 << i)) && (v[i] <= s[p])) c.push_back(i);
dp[p][mask] = -1;
for (int i = 0; i < (1 << c.size()); i++) {
int sum = 0;
int newMask = mask;
for (int j = 0; j < c.size(); j++) {
if (i & (1 << j)) {
sum += v[c[j]];
newMask |= (1 << c[j]);
}
}
if (sum == s[p]) {
dp[p][mask] = max(dp[p][mask], solve(p + 1, newMask));
if (dp[p][mask] == 1) return 1;
}
}
return dp[p][mask];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
s.resize(n);
v.resize(m);
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < m; i++) cin >> v[i];
sort(all(s));
sort(all(v));
solve(0, 0);
cout << (dp[0][0] == 1 ? "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... |