Submission #524249

#TimeUsernameProblemLanguageResultExecution timeMemory
524249macktvzBurza (COCI16_burza)C++17
0 / 160
549 ms524292 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),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'; }

Compilation message (stderr)

burza.cpp: In function 'int main()':
burza.cpp:38:25: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   38 |                 if (j&i == 0) {
      |                       ~~^~~~
burza.cpp:37:29: warning: 'ch' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |             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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...