# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
831386 | NoLove | Bank (IZhO14_bank) | C++14 | 1085 ms | 340 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.
/**
* author : Lăng Trọng Đạt
* created: 2023-08-19
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
using pii = pair<int, int>;
vector<int> a, b;
int n, m;
bool dfs(int pos, vector<int>& tmp) {
if (pos == n) return true;
for (int mask = 1; mask < (1 << tmp.size()); mask++) {
int total = 0;
for (int j = 0; j < tmp.size(); j++)
if (mask & (1 << j))
total += tmp[j];
if (total == a[pos]) {
vector<int> tmp_new;
for (int j = 0; j < tmp.size(); j++)
if (!(mask & (1 << j)))
tmp_new.push_back(tmp[j]);
if (dfs(pos + 1, tmp_new)) {
db(pos, total, a[pos], mask, bitset<6>(mask))
return true;
}
}
}
return false;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("hi.inp", "r")) {
freopen("hi.inp", "r", stdin);
// freopen("hi.out", "w", stdout);
}
cin >> n >> m;
a.resize(n); b.resize(m);
for (auto& i : a) cin >> i;
for (auto& i : b) cin >> i;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
cout << (dfs(0, b) ? "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... |