Submission #891652

#TimeUsernameProblemLanguageResultExecution timeMemory
891652ind1vBank (IZhO14_bank)C++11
25 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a, b; namespace sub1 { bool check() { return n == 1 && m <= 20; } void solve() { bool f = true; for (int msk = 0; msk < (1 << m); msk++) { int tot = 0; for (int i = 0; i < m; i++) { tot += (msk >> i & 1) * b[i]; } f |= (tot == a[0]); } cout << (f ? "YES" : "NO") << '\n'; } } namespace sub2 { bool check() { return n <= 10 && m <= 10; } int w[1 << 10]; int f[10][1 << 10]; int dp(int id, int msk) { if (id == -1) { return true; } int &res = f[id][msk]; if (res != -1) { return res; } res = 0; for (int sm = 0; sm < (1 << m); sm++) { if (w[sm] == a[id] && ((msk & sm) == sm)) { res |= dp(id - 1, msk ^ sm); } } return res; } void solve() { memset(w, 0, sizeof(w)); for (int msk = 0; msk < (1 << m); msk++) { for (int i = 0; i < m; i++) { w[msk] += (msk >> i & 1) * b[i]; } } memset(f, -1, sizeof(f)); cout << (dp(n - 1, (1 << m) - 1) ? "YES" : "NO") << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } b.resize(m); for (int i = 0; i < m; i++) { cin >> b[i]; } if (sub1::check()) { sub1::solve(); exit(0); } if (sub2::check()) { sub2::solve(); exit(0); } 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...