Submission #334500

#TimeUsernameProblemLanguageResultExecution timeMemory
334500PetyBank (IZhO14_bank)C++14
100 / 100
80 ms6508 KiB
#include <iostream> #include <vector> #include <stdlib.h> #include <algorithm> using namespace std; int n, m, a[22], b[22]; vector<int>Masks[1002]; bool viz[20][(1 << 20)]; void backt (int k, int mask) { if (k == n) { cout << "YES\n"; exit(0); } if (viz[k][mask]) return; viz[k][mask] = 1; for (auto it : Masks[a[k]]) { if (mask & it) continue; backt(k + 1, mask | it); } return; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < m; j++) cin>> b[j]; sort(a, a + n); sort(b, b + m); for (int i= 0; i < n; i++) for (int j = 0; j < m; j++) if (a[i] == b[j]) { swap(a[i], a[n - 1]); swap(b[j], b[m - 1]); n--; m--; i = -1; break; } if (n > m / 2) { cout << "NO\n"; return 0; } for (int mask = 0; mask < (1 << m); mask++) { int sum = 0; for (int j = 0; j < m; j++) if (mask & (1 << j)) sum += b[j]; if (sum <= 1000) Masks[sum].push_back(mask); } backt(0, 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...