Submission #13513

#TimeUsernameProblemLanguageResultExecution timeMemory
13513tncks0121Bank (IZhO14_bank)C++14
100 / 100
247 ms14700 KiB
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <string> #include <functional> #include <vector> #include <deque> #include <utility> #include <bitset> #include <limits.h> #include <time.h> using namespace std; typedef long long ll; typedef unsigned long long llu; typedef double lf; typedef unsigned int uint; typedef long double llf; typedef pair<int, int> pii; const int Z = 20; int N, M, A[Z], B[Z]; bool visited[Z][1 << Z]; vector<int> S[Z]; void backtrack(int i, int state) { if (i == N) { puts("YES"); exit(0); } 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() { scanf("%d%d", &N, &M); for (int i = 0; i < N; i++) scanf("%d", A + i); for (int j = 0; j < M; j++) scanf("%d", B + j); 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); puts("NO"); return 0; }

Compilation message (stderr)

bank.cpp: In function 'void backtrack(int, int)':
bank.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int e = 0; e < S[i].size(); e++) {
                  ~~^~~~~~~~~~~~~
bank.cpp: In function 'int main()':
bank.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:54:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < N; i++) scanf("%d", A + i);
                              ~~~~~^~~~~~~~~~~~~
bank.cpp:55:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int j = 0; j < M; j++) scanf("%d", B + j);
                              ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...