Submission #321041

#TimeUsernameProblemLanguageResultExecution timeMemory
321041tushar_2658Bank (IZhO14_bank)C++14
100 / 100
534 ms15588 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 21; bool dp[maxn][1 << maxn]; int a[maxn], b[maxn]; int n, m; vector<int> make[maxn]; int main(int argc, char const *argv[]) { scanf("%d %d", &n, &m); for(int i = 0; i < n; ++i){ scanf("%d", &a[i]); } for(int i = 0; i < m; ++i){ scanf("%d", &b[i]); } for(int mask = 0; mask < (1 << m); ++mask){ int sum = 0; for(int i = 0; i < m; ++i){ if((mask >> i) & 1){ sum += b[i]; } } for(int i = 0; i < n; ++i){ if(a[i] == sum){ make[i].push_back(mask); } } } for(int i = 0; i < n; ++i){ for(int mask = 0; mask < (1 << m); ++mask){ if((mask == 0 && i == 0) || (i > 0 && dp[i - 1][mask])){} else continue; for(auto nmask : make[i]){ if((nmask & mask) == 0){ dp[i][(nmask ^ mask)] = 1; } } } } bool good = 0; for(int i = 0; i < (1 << m); ++i){ if(dp[n - 1][i]){ good = 1; break; } } good ? cout << "YES" << '\n' : cout << "NO" << '\n'; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main(int, const char**)':
bank.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
bank.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d", &b[i]);
      |     ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...