제출 #519572

#제출 시각아이디문제언어결과실행 시간메모리
519572Alex_tz307은행 (IZhO14_bank)C++17
100 / 100
437 ms3120 KiB
#include <bits/stdc++.h> using namespace std; void testCase() { int n, m; cin >> n >> m; vector<int> a(n + 1), b(m); for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int &x : b) { cin >> x; } vector<vector<int>> states(n + 1); for (int mask = 1; mask < (1 << m); ++mask) { int sum = 0; for (int i = 0; (1 << i) <= mask; ++i) { if (mask & (1 << i)) { sum += b[i]; } } for (int i = 1; i <= n; ++i) { if (a[i] == sum) { states[i].emplace_back(mask); } } } vector<vector<bool>> can(n + 1, vector<bool>(1 << m)); can[0][0] = true; for (int i = 1; i <= n; ++i) { for (int mask = 0; mask < (1 << m); ++mask) { if (can[i - 1][mask]) { for (int x : states[i]) { if ((mask & x) == 0) { can[i][mask | x] = true; } } } } } if (count(can[n].begin(), can[n].end(), true)) { cout << "YES\n"; } else { cout << "NO\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } 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...