제출 #863621

#제출 시각아이디문제언어결과실행 시간메모리
863621grate은행 (IZhO14_bank)C++17
100 / 100
84 ms16984 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pll pair<ll, ll> #define ppll pair<pll, ll> #define fll(i, n) for (ll i =0 ; i < n; i++) #define vll vector<ll> #define prtv(V) fll(i, V.size()) cout << V[i] << " "; cout << '\n'; ll INF = 2e18; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n, m; cin >> n >> m; vll A(n), B(m); fll(i, n) cin >> A[i]; fll(i, m) cin >> B[i]; A.push_back(0); vector<pll> ans(1<<m, {0, INF}); ans[0] = {0, A[0]}; fll(s, 1<<m) { if (ans[s].first == n && !ans[s].second) { cout << "YES\n"; return 0; } if (ans[s].second == INF) continue; fll(i, m) if (!(s&(1<<i))) { if (ans[s].second == B[i]) ans[s|(1<<i)] = {ans[s].first+1, A[ans[s].first+1]}; else if (ans[s].second > B[i]) ans[s|(1<<i)] = {ans[s].first, ans[s].second-B[i]}; } } 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...