Submission #606109

#TimeUsernameProblemLanguageResultExecution timeMemory
606109jjianglyBank (IZhO14_bank)C++14
44 / 100
1088 ms316 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define siz(x) int(x.size()) #define ll long long #define ar array #define vt vector #define inf INT_MAX #define lnf LLONG_MAX const int nxm = int(2e5) + 7; int n, m, a[25], b[25]; namespace sub1 { void exe() { bool ok = false; function<void(int, int)> work = [&](int idx, int v) { if (idx == m) { ok = (v == a[0] ? true : ok); return; } work(idx + 1, v + b[idx]); work(idx + 1, v); }; work(0, 0); cout << (ok ? "YES" : "NO") << "\n"; } }; namespace sub2 { void exe() { vt<int> p(m); iota(all(p), 0); bool ok = false; do { int cnt = 0, sum = 0; for (int i = 0; i < m; ++i) { sum += b[p[i]]; if (sum == a[cnt]) { ++cnt; sum = 0; } if (cnt >= n) { break; } } if (cnt == n) { ok = true; } } while (next_permutation(all(p))); cout << (ok ? "YES" : "NO") << "\n"; } }; namespace sub3 { void exe() { vt<vt<int>> f(n); for (int i = 0; i < n; ++i) { function<void(int, int, int)> work = [&](int idx, int v, int mask) { if (idx == m) { if (v == a[i]) { f[i].push_back(mask); } return; } work(idx + 1, v + b[idx], mask | (1 << idx)); work(idx + 1, v, mask); }; work(0, 0, 0); } vt<vt<bool>> dp(n, vt<bool> ((1 << m), false)); for (int i = 1; i < n; ++i) { for (int mask = 0; mask < (1 << m); ++mask) { if (dp[i - 1][mask]) { for (int v : f[i]) { if (mask | v == mask) { dp[i][mask ^ v] = true; } } } } } bool ok = false; for (int mask = 0; mask < (1 << m); ++mask) { if (dp[n - 1][mask]) { ok = true; } } cout << (ok ? "YES" : "NO") << "\n"; } }; int subtask() { if (n == 1) { return 1; } else if (n <= 10) { return 2; } else if (n <= 20 && m <= 14) { return 3; } return 4; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } if (n > m) { cout << "NO\n"; } if (subtask() == 1) { sub1::exe(); } else if (subtask() == 2) { sub2::exe(); } else if (subtask() == 3) { sub3::exe(); } return 0; }

Compilation message (stderr)

bank.cpp: In function 'void sub3::exe()':
bank.cpp:77:26: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   77 |             if (mask | v == mask) {
      |                        ~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...