| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 847766 | vjudge1 | Bank (IZhO14_bank) | C++17 | 147 ms | 8872 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;
const int N = 21, M = (1 << 20) + 4;
int n, m, a[N], b[N];
pair<int, int> memo[M];
pair<int, int> solve(int msk) {
if(!msk)
return {0, 0};
auto &ret = memo[msk];
if(~ret.first)
return ret;
ret = {0, 0};
for(int j = 0; j < m ; ++j) {
if((msk >> j) & 1) {
auto cur = solve(msk - (1 << j));
if(cur.second + b[j] == a[cur.first])
cur.first++, cur.second = 0;
else cur.second += b[j];
ret = max(ret, cur);
}
}
return ret;
}
int main() {
// freopen("input.in", "r", stdin);
cin >> n >> m;
for(int i = 0 ; i < n ;++i)
cin >> a[i];
for (int i = 0; i < m; ++i)
cin >> b[i];
memset(memo, -1, sizeof memo);
cout << (solve((1 << m) - 1).first >= n ? "YES" : "NO") << "\n";
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... | ||||
