Submission #919673

#TimeUsernameProblemLanguageResultExecution timeMemory
919673dubabubaBank (IZhO14_bank)C++14
71 / 100
1022 ms185748 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 21; const int mxa = 1010; vector<int> bit[mxa * mxn]; int sum[1 << mxn]; int n, a[mxn]; int m, b[mxn]; int dp[mxn][1 << mxn]; int solve(int i, int cur) { if(i == 0) return 1; if(dp[i][cur] > -1) return dp[i][cur]; int val = a[i]; dp[i][cur] = 0; for(int las : bit[val]) { bool sus = true; for(int j = 0; j < m; j++) { if(las & (1 << j)) { if((cur & (1 << j)) == 0) { sus = false; } } } // bool sus = ((las | cur) == cur) && ((las & cur) == las); if(sus && solve(i - 1, cur ^ las)) dp[i][cur] = 1; } return dp[i][cur]; } int main() { cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int j = 0; j < m; j++) cin >> b[j]; for(int cur = 0; cur < (1 << m); cur++) { int sus, prv; for(sus = 0; sus < m; sus++) if(cur & (1 << sus)) break; prv = cur ^ (1 << sus); sum[cur] = sum[prv] + b[sus]; bit[sum[cur]].push_back(cur); } for(int i = 0; i < mxn; i++) for(int cur = 0; cur < (1 << mxn); cur++) dp[i][cur] = -1; if(solve(n, (1 << m) - 1)) cout << "YES\n"; else cout << "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...