Submission #1073232

#TimeUsernameProblemLanguageResultExecution timeMemory
1073232vjudge1Bank (IZhO14_bank)C++17
100 / 100
402 ms15572 KiB
#include <bits/stdc++.h> using namespace std; const int Z = 20; int N, M, A[Z], B[Z]; bool visited[Z][1 << Z]; vector<int> S[Z]; bool ans = false; void backtrack(int i, int state) { if (i == N) { ans = true; return; } if (visited[i][state]) return; visited[i][state] = true; for (int e = 0; e < S[i].size(); e++) { int s = S[i][e]; if (state & s) continue; backtrack(i + 1, state | s); } } 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 = 0; 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); } backtrack(0, 0); if (ans) cout << "YES\n"; else cout << "NO\n"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'void backtrack(int, int)':
bank.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int e = 0; e < S[i].size(); e++) {
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...