제출 #524256

#제출 시각아이디문제언어결과실행 시간메모리
524256macktvz은행 (IZhO14_bank)C++17
71 / 100
886 ms262148 KiB
#include <bits/stdc++.h> using namespace std; // can we split B into disjoint subsets s.t. there is at least one subset per Ai // for multiple A, need to find subsets that satisfy each A and & to 0 // dp[MASK] = TRUE if int main() { int n,m; cin >> n >> m; vector<int> A(n); vector<int> B(m); for(auto &a : A) cin >> a; for(auto &b : B) cin >> b; vector<vector<int>> S(n); // with some sum there are only sqrt(sum) different possible values for(int mask = 0; mask < (1<<m); mask++) { int s = 0; for(int i = 0; i < m; i++) { if (mask&(1<<i)) s += B[i]; } for(int i = 0; i < n; i++) { if (s == A[i]) S[i].push_back(mask); } } vector<vector<int>> dp((1 << n)); for(int i = 0; i < n; i++) { dp[1<<i]=S[i]; } for(int mask = 0; mask < (1 << n); mask++) { if (__builtin_popcount(mask) <= 1) continue; int ch; for(int i = 0; i < n; i++) { // find first bit set if (mask&(1<<i)) { ch = i; break; } } for(int j : dp[mask^(1<<ch)]) { for(int i : S[ch]) { if ((j&i) == 0) { dp[mask].push_back(j|i); } } } } int sz = (int)dp[(1<<n)-1].size(); cout << (sz == 0 ? "NO" : "YES") << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'int main()':
bank.cpp:38:29: warning: 'ch' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |             for(int i : S[ch]) {
      |                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...