제출 #848018

#제출 시각아이디문제언어결과실행 시간메모리
848018_hbk06은행 (IZhO14_bank)C++14
100 / 100
106 ms16992 KiB
#include<bits/stdc++.h> using namespace std; const int mxN = 5e5 + 5; #define int long long #define MASK(n) (1 << (n)) #define BIT(mask,x) ((mask >> x) & 1) const long long infll = 1e18 + 69; int n; int m; int a[20]; int b[20]; int s[MASK(20)]; pair<int,int> dp[MASK(20)]; signed main () { // freopen("bank.in","r",stdin); // freopen("bank.out","w",stdout); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; dp[0] = make_pair(0,0); for (int mask = 0; mask < MASK(m); mask++) for (int i = 0; i < m; i++) { if(BIT(mask,i)) continue; pair<int,int> new_state; if(a[dp[mask].first] == dp[mask].second + b[i]) new_state = make_pair(dp[mask].first + 1,0); else new_state = make_pair(dp[mask].first,dp[mask].second + b[i]); dp[mask ^ MASK(i)] = max(dp[mask ^ MASK(i)],new_state); } bool kt = false; for (int mask = 0; mask < MASK(m); mask++) if(dp[mask].first == n) {kt = true;break;} if(kt) cout << "YES" << "\n"; else cout << "NO" << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...