Submission #1084648

#TimeUsernameProblemLanguageResultExecution timeMemory
1084648vjudge1Bank (IZhO14_bank)C++17
44 / 100
551 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int Z = 20; int N, M, A[Z], B[Z]; vector<int> S[Z]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < M; i++) cin >> B[i]; for (int state = 1; state < (1 << M); state++) { int sum = 0; for (int i = 0; i < M; i++) if (state & (1 << i)) sum += B[i]; for (int i = 0; i < N; i++) if (sum == A[i]) S[i].push_back(state); } vector<int> dp[1<<N]; // dp[s] : states of subset S //dp[0] = empty for (int s = 1; s < (1<<N); s++) { for (int i = 0; i < N; i++) { if (!(s & (1<<i))) continue; if (dp[s^(1<<i)].empty()) { if (__builtin_popcount(s) == 1) dp[s] = S[i]; continue; } for (auto cur_state : S[i]) for (auto prev_state : dp[s^(1<<i)]) { if (cur_state & prev_state) continue; dp[s].push_back(cur_state | prev_state); } } } if (dp[(1<<N)-1].empty()) cout << "NO"; else cout << "YES"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:47:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   47 |     else
      |     ^~~~
bank.cpp:50:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   50 |  return 0;
      |  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...