Submission #1001854

#TimeUsernameProblemLanguageResultExecution timeMemory
1001854coin_Bank (IZhO14_bank)C++14
100 / 100
99 ms34480 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(22); 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...