제출 #1017147

#제출 시각아이디문제언어결과실행 시간메모리
1017147daviedu은행 (IZhO14_bank)C++17
19 / 100
82 ms8636 KiB
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0); cin.tie(0) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ll long long struct P{ ll x, y; }; void dbg_out() { cerr << endl; } template <typename H, typename... T> void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); } #define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); } const int MAXN = 1<<20; int dp[MAXN], r[MAXN]; signed main(){ fastio; memset(dp, -1, sizeof(dp)); int n, m; cin >> n >> m; vector<int> pay (n), notes (m); for (auto &a: pay) cin >> a; for (auto &a: notes) cin >> a; bool ans=false; for (int mask=1; mask<(1<<m); mask++){ for (int i=0; i<m; i++){ if (!(mask & (1 << i))) continue; int p = mask ^ (1 << i); int goal = dp[p]+1; if (goal <= dp[mask]) continue; if (r[p] + notes[i] == pay[goal]){ dp[mask] = goal; r[mask] = 0; break; } else{ dp[mask] = dp[p]; r[mask] = r[p] + notes[i]; } if (dp[mask] == n-1) { ans = true; } } } cout << (ans? "YES" : "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...