Submission #80904

#TimeUsernameProblemLanguageResultExecution timeMemory
80904farukkastamonudaBank (IZhO14_bank)C++14
52 / 100
1076 ms22864 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]; map <int, int> mp[1005]; vector<int> v[22]; void dfs(int sayi, int msk, int ind){ if(mp[sayi][msk] == 1) return ; if(sayi == 0){ v[ind].pb(msk); mp[sayi][msk] = 1; return ; } mp[sayi][msk] = 1; int flag = 0; for(int i = 1;i <= m; i++){ if(!(msk&(1 << (i - 1)))){ if(sayi >= B[i]){ flag = 1; dfs(sayi - B[i], msk | (1 << (i - 1)), ind); } } } if(flag == 0) return ; } void solve(int node, int msk){ if(node == n + 1){ printf("YES\n"); exit(0); } //if(dp[node][msk]) 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 <= n; i ++){ dfs(A[i], 0, i); for(int j = 0; j <= 1000 ; j ++) mp[j].clear(); } solve(1, 0); printf("NO\n"); return 0; }

Compilation message (stderr)

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