Submission #80907

#TimeUsernameProblemLanguageResultExecution timeMemory
80907farukkastamonudaBank (IZhO14_bank)C++14
100 / 100
196 ms18812 KiB
#include <bits/stdc++.h> #define fi first #define se second #define lo long long #define inf 1000000000 #define md 1000000007 #define li 2005 #define mpt make_pair #define pb push_back using namespace std; int n, m, A[22], B[22], sum[(1 << 20) + 5]; vector<int> v[22]; bool dp[22][(1 << 20) + 5]; void solve(int node, int msk){ if(node == n + 1){ printf("YES\n"); exit(0); } if(dp[node][msk] == true) return ; dp[node][msk]=true; for(int i = 0; i < (int)v[node].size(); i ++){ if(! (msk & v[node][i]) ) solve(node + 1, msk | v[node][i]); } } int main(){ scanf("%d %d", &n, &m); for(int i = 1; i <= n; i ++){ scanf("%d", &A[i]); } for(int i = 1; i <= m; i ++){ scanf("%d", &B[i]); } for(int i = 1; i < (1 << m) ; i ++){ for(int j = 0; j < m; j ++){ if(i&(1 << j)){ sum[i] = sum[i - (1 << j)] + B[j + 1]; break; } } } for(int i = 1; i <= n; i ++){ for(int j = 0; j < (1 << m) ; j ++){ if(A[i] == sum[j]){ v[i].pb(j); } } } solve(1, 0); printf("NO\n"); return 0; }

Compilation message (stderr)

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