Submission #169135

#TimeUsernameProblemLanguageResultExecution timeMemory
169135LinusTorvaldsFanBank (IZhO14_bank)C++14
71 / 100
72 ms632 KiB
#include <iostream> #include <vector> #include <memory.h> using namespace std; const int N = 20; const int M = 14; const int masks = 1 << M; bool dp[masks][N]; int main() { int n, m; cin >> n >> m; vector<int>a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int>b(m); for (int i = 0; i < m; i++) { cin >> b[i]; } if (n == 1) { for (int mask = 0; mask < (1 << m); mask++) { int cur = 0; for (int j = 0; j < m; j++) { if (mask & (1 << j)) { cur += b[j]; } } if (cur == a[0]) { cout << "YES"; return 0; } } cout << "NO"; return 0; } if (n <= 20 && m <= 14) { memset(dp, 0, sizeof(dp)); dp[0][0] = true; for (int mask = 0; mask < (1 << m); mask++) { for (int j = 0; j < n; j++) { if (!dp[mask][j])continue; int lost = (~mask + (1<<m)) % (1 << m); for (int submask = lost;; submask = (submask - 1) & lost) { int sum = 0; for (int t = 0; t < m; t++) { if (submask & (1 << t)) { sum += b[t]; } } if (sum == a[j]) { dp[mask + submask][j + 1] = true; } if (submask == 0)break; } } } for (int mask = 0; mask < (1 << m); mask++) { if (dp[mask][n]) { cout << "YES"; return 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...