Submission #1089356

#TimeUsernameProblemLanguageResultExecution timeMemory
1089356vjudge1Bank (IZhO14_bank)C++17
0 / 100
110 ms262144 KiB
#include <bits/stdc++.h> //qwerty47924692 using namespace std; using ll = int; #define f first #define s second const ll N=2e7+29; ll n,m,a[N],b[N],ans,used[N],dp[N]; vector<ll>masks[N]; void dfs(ll v,ll mask){ used[mask]=1; if(v==n+1){ cout<<"YES"; exit(0); }for(ll to:masks[v]){ if(!(to&mask)&&!used[mask|to]){ dfs(v+1,mask|to); } } } void f(ll x,ll sum=0,ll mask=0){ if(x==m){ for(ll i=1;i<=n;i++){ if(sum==a[i])masks[i].push_back(mask); } return; } x++; f(x,sum+b[x],mask|(1ll<<(x-1))); f(x,sum,mask); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for(ll i=1;i<=n;i++){ cin>>a[i]; } for(ll i=1;i<=m;i++){ cin>>b[i]; } f(0); dfs(1,0); cout<<(ans ? "YES" : "NO"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...