제출 #660233

#제출 시각아이디문제언어결과실행 시간메모리
660233hafo은행 (IZhO14_bank)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define pb push_back #define pa pair<int, int> #define pall pair<ll, int> #define fi first #define se second #define TASK "test" #define all(x) x.begin(), x.end() using namespace std; template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;} const int MOD = 1e9 + 7; const int LOG = 20; const int maxn = 20 + 7; const ll oo = 1e15 + 69; int n, m, a[maxn], b[maxn]; pa dp[1 << 20]; bool getbit(const int mask, const int i) { return ((mask >> i) & 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen(TASK".inp", "r", stdin); //freopen(TASK".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]; fill_n(dp, (1 << n), make_pair(0, 0)); dp[0] = {1, 0}; for(int mask = 0; mask < (1 << n); mask++) for(int i = 0; i < n; i++) if(!getbit(mask, i)) { int id = dp[mask].fi, s = dp[mask].se; if(s + a[i] == b[id - 1]) { id++; s = 0; } else s += a[i]; maxi(dp[mask | (1 << i)], make_pair(id, s)); } cout<<(dp[(1 << n) - 1].fi == n ? "YES":"NO"); 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...