Submission #850539

#TimeUsernameProblemLanguageResultExecution timeMemory
850539moonpayBank (IZhO14_bank)C++17
0 / 100
26 ms600 KiB
//#pragma GCC target("avx2") //#pragma GCC optimize("O3") #include <bits/stdc++.h> #define int int64_t using namespace std; const int maxn = 2e5 + 10; const int modm = 1e9 + 7; void print(vector<int> &t) { for (auto &r: t) { cout << r << " "; } cout << "\n"; } bool solve(multiset<int> &a, multiset<int> &b, int n, int m) { vector<int> af, bs; for (auto z: a) { af.push_back(z); } sort(af.begin(), af.end()); for (auto z: b) { bs.push_back(z); } bool dp[(1 << m)][n + 1]; for (int i = 0; i < (1 << m); i++) { for (int j = 0; j < n + 1; j++) { dp[i][j] = false; } } for (int i = 0; i < (1 << m); i++) { dp[i][0] = true; } vector<int> sum(1 << m, 0); for (int i = 1; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if (i & (1 << j)) { sum[i] = sum[i ^ (1 << j)] + bs[j]; } } } for (int mask = 0; mask < (1 << m); mask++) { for (int lm = mask; lm > 0; lm = (lm - 1) & mask) { int sm = sum[lm]; for (int i = 1; i <= n; i++) { if (sm == af[i - 1]) { dp[mask][i] = dp[mask ^ lm][i - 1]; } } } } return dp[(1 << m) - 1][n]; } int32_t main() { int n, m; cin >> n >> m; multiset<int> f, s, q; for (int i = 0; i < n; i++) { int a; cin >> a; f.insert(a); q.insert(a); } for (int j = 0; j < m; j++) { int a; cin >> a; s.insert(a); } for (auto z: f) { if (s.find(z)!= s.end()) { q.extract(q.find(z)); s.extract(s.find(z)); } } if (q.size() == 0) { std::cout << "Yes\n"; return 0; } if (q.size() * 2 > s.size()) { std::cout << "No\n"; } else { std::cout << (solve(q, s, q.size(), s.size()) ? "Yes" : "No"); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...