Submission #710933

#TimeUsernameProblemLanguageResultExecution timeMemory
710933HeartBreakKidBank (IZhO14_bank)C++17
100 / 100
115 ms16844 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define pk pop_back #define yes cout << "YES\n" #define no cout << "NO\n" using namespace std; ll n, m, k, mod = 1e9 + 7; map<ll, ll> mp; string s; pair <ll, ll> dp[1100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); cin >> n >> m; vector <ll> a(n + 1); vector <ll> b(m + 1); for (ll i = 1; i <= n; ++i) { cin >> a[i]; } for (ll i = 1; i <= m; ++i) { cin >> b[i]; } for (ll mask = 1; mask < (1 << m); ++mask) { for (ll cur = 0; cur < m; ++cur) { if ((mask >> cur) & 1) { ll pred_mask = mask ^ (1 << cur); ll total = dp[pred_mask].second + b[cur + 1]; ll done = dp[pred_mask].first; if (done < n && a[done + 1] == total && dp[mask].first <= done) { dp[mask] = {done + 1, 0}; } else { if (dp[mask].first <= done) { dp[mask] = {done, total}; } } } } } if (dp[(1 << m) - 1].first == n) { 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...