Submission #340087

#TimeUsernameProblemLanguageResultExecution timeMemory
340087_aniBank (IZhO14_bank)C++17
100 / 100
426 ms52920 KiB
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> using namespace std; vector<int> dp[22]; vector<int> sums[1002]; int su[1002][22]; int a[22], b[22]; int n, m; int used[22][(1 << 20) + 1]; int getsum(int mask) { int res = 0; int ind = m - 1; while (mask) { if (mask & 1) res += b[ind]; mask >>= 1; ind--; } return res; } 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 i = 1; i < (1 << m); i++) if (getsum(i) <= 1000) { sums[getsum(i)].push_back(i); } for (auto s : sums[a[0]]) used[0][s] = 1; for (auto i : sums[a[0]]) dp[0].push_back(i); for (int i = 1; i < n; i++) { if (dp[i - 1].empty()) { cout << "NO\n"; return 0; } for (int j = 0; j < (int)dp[i - 1].size(); j++) for (auto k: sums[a[i]]) if ((dp[i - 1][j] & k) == 0 && used[i][dp[i - 1][j] | k] == 0) { dp[i].push_back(dp[i - 1][j] | k); used[i][dp[i - 1][j] | k] = 1; } } if (dp[n - 1].empty()) cout << "NO\n"; else cout << "YES\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...