Submission #1088201

#TimeUsernameProblemLanguageResultExecution timeMemory
1088201T0p_Bank (IZhO14_bank)C++14
71 / 100
178 ms182096 KiB
#include <bits/stdc++.h> using namespace std; const int N = 20; int a[N], b[N], dp[N][1<<N]; vector<int> sum_to_bit[20001]; int solve(int n, int s) { if (dp[n][s] != -1) { return dp[n][s]; } if (n == 0) { return dp[n][s] = 1; } int res = 0; for (int bit : sum_to_bit[a[n-1]]) { if ((bit & s) == bit) { res |= solve(n-1, bit ^ s); } } return dp[n][s] = res; } int main() { int n, m; 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 i=0 ; i<1<<m ; i++) { int sum = 0; for (int j=0 ; j<m ; j++) { if (i & (1<<j)) { sum += b[j]; } } sum_to_bit[sum].push_back(i); } memset(dp, -1, sizeof(dp)); printf(solve(n, (1<<m)-1) == 1 ? "YES\n" : "NO\n"); return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf(" %d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
bank.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf(" %d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~~
bank.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     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...