Submission #38759

#TimeUsernameProblemLanguageResultExecution timeMemory
38759khohkoBank (IZhO14_bank)C++14
100 / 100
760 ms22296 KiB
#include <bits/stdc++.h> using namespace std; #define ll int #define pb push_back #define fr first #define sc second #define N ((ll)(2e5+100)) #define MAX ((ll)(1e16+100)) #define ARRS ((ll)(2e5+100)) #define MOD ((ll)(1e9+7)) #define pb push_back char dp[22][1060000]; ll a[40]; ll s[2000000]; ll b[40]; ll n,m; int main(){ cin>>n>>m; for(int i=0; i<n; i++) cin>>b[i]; for(int i=1; i<n; i++) b[i]+=b[i-1]; for(int i=0; i<m; i++) cin>>a[i]; s[0]=0; for(int t=0; t<(1<<m); t++) for(int j=0; j<m; j++) if(!((t>>j)&1)) s[t|(1<<j)]=s[t]+a[j]; ll pas=0; dp[0][0]=1; for(int i=0; i<=n; i++){ for(int t=0; t<(1<<m); t++){ if(!dp[i][t])continue; if(i==n){ pas=1; break; } if(s[t]==b[i]) dp[i+1][t]=1; for(int j=0; j<m; j++) if(!((t>>j)&1))dp[i][t|(1<<j)]=1; } } if(pas) cout<<"YES"; else cout<<"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...