Submission #141557

#TimeUsernameProblemLanguageResultExecution timeMemory
141557meatrowBank (IZhO14_bank)C++17
100 / 100
277 ms17796 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> lst[M]; int dp[M][N]; 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; } n = a.size(); m = b.size(); int topkek = 1 << m; for (int mask = 1; mask < topkek; mask++) { int cnt = 0; for (int i = 0; i < m; i++) { if (mask & (1 << i)) { s[mask] += b[i]; cnt++; } } if (s[mask] < V) { g[s[mask]].push_back(mask); } if (s[mask] == a[0]) { dp[0][mask] = 1; } lst[cnt].push_back(mask); } for (int i = 1; i < n; i++) { for (int cnt = i * 2; cnt <= m; cnt++) { for (int mask : lst[cnt]) { if (!dp[i - 1][mask]) { continue; } for (int kek = mask; kek < topkek; kek = (kek + 1) | mask) { if (s[mask ^ kek] == a[i]) { dp[i][kek] = 1; } } } } } for (int i = 0; i < topkek; i++) { if (dp[n - 1][i]) { cout << "YES"; return 0; } } cout << "NO"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:35:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (it1 < a.size() && it2 < b.size()) {
            ~~~~^~~~~~~~~~
bank.cpp:35:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (it1 < a.size() && it2 < b.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...