Submission #1001819

#TimeUsernameProblemLanguageResultExecution timeMemory
1001819kustizusBank (IZhO14_bank)C++17
100 / 100
435 ms4948 KiB
#include <bits/stdc++.h> using namespace std; const int N=20,B=1048576; int n,m,a[N+5],b[N+5],pre[N+5],cnt[B+5]; vector <bool> dp(B+5),dp1(B+5); void Solve(){ cin>>n>>m; for (int i=1;i<=n;++i){ cin>>a[i]; pre[i]=pre[i-1]+a[i]; } for (int i=1;i<=m;++i) cin>>b[i]; int mx=(1<<m); for (int i=1;i<mx;++i) for (int j=0;j<m;++j) if ((i>>j)&1) cnt[i]+=b[j+1]; dp[0]=true; for (int i=1;i<=n;++i){ for (int mask=1;mask<mx;++mask){ if (pre[i]!=cnt[mask]) continue; for (int s=mask;;s=(s-1)&mask){ if (cnt[s^mask]==a[i] && dp[s]){ dp1[mask]=true; break; } if (!s) break; } } dp=dp1; for (int mask=0;mask<mx;++mask) dp1[mask]=false; } for (int i=1;i<mx;++i) if (dp[i]){ cout<<"YES"; return; } cout<<"NO"; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen ("FILE.INP","r",stdin); // freopen ("FILE.OUT","w",stdout); int t=1; // cin>>t; while (t--) Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...