Submission #1073227

#TimeUsernameProblemLanguageResultExecution timeMemory
1073227vjudge1Bank (IZhO14_bank)C++17
0 / 100
2 ms348 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); freopen("bank.in","r",stdin); freopen("bank.out","w",stdout); 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++) {
      |                  ~~^~~~~~~~~~~~~
bank.cpp: In function 'int main()':
bank.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen("bank.in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen("bank.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...