Submission #664663

#TimeUsernameProblemLanguageResultExecution timeMemory
664663longvuBank (IZhO14_bank)C++14
100 / 100
215 ms23484 KiB
/** * author: longvu * created: 11/27/22 14:55:09 **/ #include<bits/stdc++.h> using namespace std; #define int long long #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() const int INF = numeric_limits<int>::max(); const int naxn = (int)(21); const int naxm = (int)(19001); const int mod = 1e9 + 7; template<class X, class Y> bool maximize(X& x, const Y y) { if (y > x) {x = y; return true;} return false; } template<class X, class Y> bool minimize(X& x, const Y y) { if (y < x) {x = y; return true;} return false; } int a[naxn], b[naxn], cnt[(1 << naxn)]; vector<int> memo[naxm]; bitset<(1 << naxn)> vis[naxn], dp[naxn]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } for (int mask = 0; mask < (1 << m); ++mask) { int sum = 0; for (int i = 0; i < m; ++i) { if (mask & (1 << i)) { sum += b[i]; } } cnt[mask] = __builtin_popcount(mask); memo[sum].push_back(mask); } function<bool(int, int)> solve = [&](int i, int mask) { if (i == n) { return true; } if (vis[i][mask]) { return (bool)(dp[i][mask]); } bool res = false; for (auto z : memo[a[i]]) { if (!(mask & z) && m - cnt[mask] + cnt[z] >= n - 1 - i && solve(i + 1, mask | z)) { res = true; break; } } vis[i][mask] = true; dp[i][mask] = res; return res; }; cout << (solve(0, 0) ? "YES" : "NO") << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...