제출 #798853

#제출 시각아이디문제언어결과실행 시간메모리
798853SanguineChameleon은행 (IZhO14_bank)C++17
100 / 100
152 ms19424 KiB
#include <bits/stdc++.h> using namespace std; const int maxN = 20; const int maxA = 1e3 + 20; int A[maxN]; int B[maxN]; vector<int> masks[maxA]; bool flag[maxN][1 << maxN]; int N, M; void backtrack(int pos, int cur) { if (pos == N) { cout << "YES"; exit(0); } if (flag[pos][cur]) { return; } flag[pos][cur] = true; for (auto mask: masks[A[pos]]) { if (!(cur & mask)) { backtrack(pos + 1, cur | mask); } } } int main() { 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 >> i) & 1) { sum += B[i]; } } if (sum < maxA) { masks[sum].push_back(mask); } } backtrack(0, 0); cout << "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...