Submission #1115621

#TimeUsernameProblemLanguageResultExecution timeMemory
1115621tudor_costinBank (IZhO14_bank)C++11
100 / 100
285 ms164724 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int Nmax=1005; vector<int> v[20*Nmax]; int dp[25][(1<<21)]; int sum[1<<21]; int a[25],b[25]; signed main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int j=0;j<m;j++) cin>>b[j]; for(int mask=0;mask<(1<<m);mask++) { for(int i=0;i<m;i++) { if((mask&(1<<i))!=0) { sum[mask]+=b[i]; } } v[sum[mask]].push_back(mask); } int S=0; dp[0][0]=1; for(int i=0;i<n;i++) { for(int mask=0;mask<(1<<m);mask++) { if(dp[i][mask]==1) { for(int u:v[a[i+1]]) { if((u&mask)==0) { dp[i+1][(mask|u)]=1; if(i+1==n) { cout<<"YES"<<'\n'; return 0; } } } } } } cout<<"NO"<<'\n'; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:27:9: warning: unused variable 'S' [-Wunused-variable]
   27 |     int S=0;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...