제출 #944793

#제출 시각아이디문제언어결과실행 시간메모리
944793ZHIRDILBILDIZ은행 (IZhO14_bank)C++14
100 / 100
213 ms8824 KiB
#include<bits/stdc++.h> #define fi first #define se second #define ll long long using namespace std; const int N = 20; const int NS = 10; int n, m; int a[N]; int b[N]; int sum_a; bool dp[(1 << N)]; bool abu[(1 << NS)][(1 << NS)]; vector<int> v[1001]; signed main() { // freopen("bank.in", "r", stdin); // freopen("bank.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> a[i]; sum_a += a[i]; } for (int i = 0; i < m; ++i) cin >> b[i]; if (n > m) { cout << "NO\n"; return 0; } if (n == 1) { for (int i = 0; i < (1 << m); ++i) { int sum = 0; for (int j = 0; j < m; ++j) sum += b[j] * ((i & (1 << j)) > 0); if (sum == a[0]) { cout << "YES\n"; return 0; } } cout << "NO\n"; return 0; } for (int i = 0; i < (1 << m); ++i) { int sum = 0; for (int j = 0; j < m; ++j) sum += b[j] * ((i & (1 << j)) > 0); if (sum <= 1e3) v[sum].push_back(i); } // if (n <= 10 && m <= 10) { // abu[0][0] = 1; // for (int i = 0; i < (1 << m); ++i) // for (int j = 0; j < (1 << n); ++j) // for (int q = 0; q < n; ++q) // if (((1 << q) & j)) // for (int z : v[a[q]]) // if ((z & i) == z) { // abu[i][j] |= abu[i ^ z][j ^ (1 << q)]; // if (abu[i][j] && j == (1 << n) - 1) { // cout << "YES\n"; // return 0; // } // } // cout << "NO\n"; // return 0; // } vector<int> gr[2]; gr[0].push_back(0); dp[0] = 1; for (int i = 0; i < n; ++i) { for (int j : gr[0]) for (int q : v[a[i]]) { if ((j & q) || dp[j ^ q]) continue; if (i == n - 1) { cout << "YES\n"; return 0; } dp[j ^ q] = 1; gr[1].push_back(j ^ q); } swap(gr[0], gr[1]); gr[1].clear(); } 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...