제출 #762142

#제출 시각아이디문제언어결과실행 시간메모리
762142Alora은행 (IZhO14_bank)C++17
100 / 100
97 ms8532 KiB
#include <bits/stdc++.h> #define name "cownav" #define fi(i,a,b) for(int i = a; i <= b; i++) #define fid(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define f first #define se second #define pii pair<int, int> #define getbit(i, j) ((i >> j) & 1) #define pb push_back #define all(v) v.begin(), v.end() #define maxn const int M = 1e9 + 7; using namespace std; int n, m, a[22], b[22]; pii dp[1 << 21]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); // freopen(name".in", "r", stdin); // freopen(name".out", "w", stdout); cin >> n >> m; fi(i, 1, n) cin >> a[i]; fi(i, 1, m) cin >> b[i]; fi(i, 1, (1 << m) - 1) dp[i] = {-1, 0}; dp[0] = {1, 0}; bool ok = 0; fi(msk, 0, (1 << m) - 1) if(dp[msk].f != -1){ int id = dp[msk].f, w = dp[msk].se; if(id == n + 1){ok = 1; break;} fi(i, 0, m - 1) if(getbit(msk, i) == 0){ if(b[i + 1] + w == a[id]){ dp[msk + (1 << i)] = max(dp[msk + (1 << i)], {id + 1, 0}); } else dp[msk + (1 << i)] = max(dp[msk + (1 << i)], {id, w + b[i + 1]}); } } if(ok) cout << "YES"; else 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...