Submission #624336

#TimeUsernameProblemLanguageResultExecution timeMemory
624336ThinGarfieldBank (IZhO14_bank)C++11
100 / 100
103 ms8528 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define mp make_pair #define F first #define S second constexpr int maxn = 20; int n, m; int a[maxn]; int b[maxn]; pii note[1 << maxn]; // (can pay 1...k, leftover l) int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); bool ans = false; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int notes = 0; notes < (1 << m); notes++) { if (notes == 0) { note[notes] = mp(-1, 0); continue; } pii ansp = mp(-1, 0); for (int i = 0; i < m; i++) { if (!(notes & (1 << i))) continue; int prevnote = notes - (1 << i); int k = -1, l = -1; if (note[prevnote].S + b[i] == a[note[prevnote].F + 1]) { k = note[prevnote].F + 1; l = 0; } else { k = note[prevnote].F; l = note[prevnote].S + b[i]; } // if (k > ansp.F) ansp = mp(k, l); ansp = max(ansp, mp(k, l)); } note[notes] = ansp; // cout << bitset<5>(notes).to_string() << " : " << note[notes].F << '\t' << note[notes].S << // '\n'; if (ansp.F == n - 1) { ans = true; break; } } cout << (ans ? "YES\n" : "NO\n"); 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...