제출 #141548

#제출 시각아이디문제언어결과실행 시간메모리
141548meatrow은행 (IZhO14_bank)C++17
71 / 100
1073 ms12512 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; n = a.size(); 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 = 0; i + 1 < n; i++) { for (int mask : dp[i]) { int cnt = 1 << (m - __builtin_popcount(mask)); if (cnt < g[a[i + 1]].size()) { for (int kek = mask; kek < topkek; kek = (kek + 1) | mask) { if (s[kek ^ mask] == a[i + 1]) { dp[i + 1].push_back(kek); } } } else { for (int kek : g[a[i + 1]]) { if (!(kek & mask)) { dp[i + 1].push_back(mask | kek); } } } if (!dp[n - 1].empty()) { break; } } if (i + 2 == n) { break; } vector<int> tmp; for (int mask : dp[i + 1]) { bool f = true; for (int j = i + 2; j < n; j++) { bool h = false; for (int k : g[a[j]]) { if (!(k & mask)) { h = true; break; } } if (!h) { f = false; break; } } if (f) { tmp.push_back(mask); } } dp[i + 1] = tmp; } if (dp[n - 1].empty()) { cout << "NO"; } else { cout << "YES"; } return 0; }

컴파일 시 표준 에러 (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:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (cnt < g[a[i + 1]].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...