제출 #734110

#제출 시각아이디문제언어결과실행 시간메모리
734110benjaminkleyn은행 (IZhO14_bank)C++17
71 / 100
1040 ms8140 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, a[20], b[20]; vector<int> masks[20001]; set<int> masks1, masks2; void search1(int i, int cur_mask) { if (i == n / 2) { masks1.insert(cur_mask); return; } for (const int &mask : masks[a[i]]) if ((cur_mask & mask) == 0) search1(i + 1, cur_mask | mask); } void search2(int i, int cur_mask) { if (i == n) { masks2.insert(cur_mask); return; } for (const int &mask : masks[a[i]]) if ((cur_mask & mask) == 0) search2(i + 1, cur_mask | mask); } int main() { cin.tie(0)->sync_with_stdio(0); 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 mask = 0; mask < (1 << m); mask++) { int sum = 0; for (int i = 0; i < m; i++) if (mask & (1 << i)) sum += b[i]; masks[sum].push_back(mask); } search1(0, 0); search2(n / 2, 0); for (int mask1 : masks1) for (int mask2 : masks2) if ((mask1 & mask2) == 0) { cout << "YES\n"; return 0; } cout << "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...