Submission #850550

#TimeUsernameProblemLanguageResultExecution timeMemory
850550moonpayBank (IZhO14_bank)C++17
71 / 100
1025 ms11608 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]) { if (dp[mask ^ lm][i - 1]) { dp[mask][i] = true; } } } } } 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.find(z) != q.end()) { q.erase(q.find(z)); n--; s.erase(s.find(z)); } } if (q.size() == 0) { std::cout << "YES\n"; return 0; } if (2 * q.size() > s.size()) { std::cout << "NO\n"; } else { if (n == 1) { bitset<20001> qr; qr[0] = true; for (auto z: s) { qr |= (qr << z); } int u; for (auto z: q) { u = z; } if (qr[u]) { std::cout << "YES"; } else { std::cout << "NO"; } return 0; } std::cout << (solve(q, s, q.size(), s.size()) ? "YES" : "NO"); } }

Compilation message (stderr)

bank.cpp: In function 'int32_t main()':
bank.cpp:106:21: warning: 'u' may be used uninitialized in this function [-Wmaybe-uninitialized]
  106 |             if (qr[u]) {
      |                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...