Submission #141545

#TimeUsernameProblemLanguageResultExecution timeMemory
141545meatrowBank (IZhO14_bank)C++17
19 / 100
99 ms10432 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //#pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; const int M = 20; const int N = 1 << M; const int V = 1001; vector<int> g[V]; vector<int> dp[M]; int s[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); int it1 = 0, it2 = 0; while (it1 < a.size() && it2 < b.size()) { if (a[it1] == b[it2]) { a.erase(a.begin() + it1); b.erase(b.begin() + it2); continue; } if (a[it1] < b[it2]) { it1++; } else { it2++; } } if (a.empty()) { cout << "YES"; return 0; } int topkek = 1 << m; for (int mask = 0; mask < topkek; mask++) { for (int i = 0; i < m; i++) { if (mask & (1 << i)) { s[mask] += b[i]; } } if (s[mask] < V) { g[s[mask]].push_back(mask); } } dp[0] = g[a[0]]; for (int i = 1; i < n; i++) { for (int mask : dp[i]) { int cnt = 1 << (m - __builtin_popcount(mask)); if (cnt < g[a[i]].size()) { for (int kek = mask; kek < topkek; kek = (kek + 1) | mask) { if (s[kek ^ mask] == a[i]) { dp[i].push_back(kek); } } } else { for (int kek : g[a[i]]) { if (!(kek & mask)) { dp[i].push_back(mask | kek); } } } } } if (dp[n - 1].empty()) { cout << "NO"; } else { cout << "YES"; } return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (it1 < a.size() && it2 < b.size()) {
            ~~~~^~~~~~~~~~
bank.cpp:34:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (it1 < a.size() && it2 < b.size()) {
                              ~~~~^~~~~~~~~~
bank.cpp:65:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (cnt < g[a[i]].size()) {
                 ~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...