Submission #1001852

#TimeUsernameProblemLanguageResultExecution timeMemory
1001852coin_Bank (IZhO14_bank)C++17
52 / 100
51 ms69564 KiB
#include <bits/stdc++.h> #define endl '\n' #define int long long #define fi first #define se second #define pb push_back using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++){ cin >> a[i]; } for (int i = 0; i < m; i++){ cin >> b[i]; } pair<int, int> dp[(1 << m)]; int visited[(1 << m)] = {0}; dp[0] = {0, 0}; visited[0] = 1; vector<vector<int>> masks(20); for (int i = 0; i < (1 << m); i++){ masks[__builtin_popcount(i)].push_back(i); } for (int i = 0; i <= m; i++){ for (int mask: masks[i]){ if (visited[mask] == 0) continue; if (dp[mask].fi == n){ cout << "YES"; return 0; } int curperson = dp[mask].fi; for (int j = 0; j < m; j++){ int newmask = mask | (1 << j); if (mask == newmask) continue; if (dp[mask].se + b[j] > a[curperson]) continue; visited[newmask] = 1; dp[newmask] = {curperson, dp[mask].se + b[j]}; if (a[curperson] == dp[mask].se + b[j]){ dp[newmask] = {curperson+1, 0}; } } } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...