Submission #172968

#TimeUsernameProblemLanguageResultExecution timeMemory
172968VEGAnnBank (IZhO14_bank)C++14
100 / 100
826 ms22136 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define PB push_back #define all(x) x.begin(),x.end() using namespace std; const int N = 20; const int NN = (1 << N); const int PW = 10; const int oo = 2e9; const int md = 998244353; int pref[N], sum[NN], mm, a[N], b[N], n, m; bool f[N][NN]; 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]; mm = (1 << m); for (int msk = 1; msk < mm; msk++){ sum[msk] = 0; for (int j = 0; j < m; j++) if (msk & (1 << j)) sum[msk] += b[j]; } pref[0] = 0; for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i - 1]; f[0][0] = 1; for (int i = 0; i < n; i++) for (int msk = 0; msk < mm; msk++){ if (!f[i][msk]) continue; if (i < n - 1 && sum[msk] == pref[i + 1]) f[i + 1][msk] = 1; for (int j = 0; j < m; j++) if (!(msk & (1 << j))) f[i][msk ^ (1 << j)] = 1; } bool ok = 0; for (int msk = 0; msk < mm; msk++) if (f[n - 1][msk] && sum[msk] == pref[n]) { ok = 1; break; } cout << (ok ? "YES" : "NO"); 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...