# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001390 | cnn008 | Bank (IZhO14_bank) | C++17 | 405 ms | 193400 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif
#define int long long
const int N=1e5+5;
const int mod=1e9+7;
int n,m,a[25],b[25],dp[25][1<<20+2],cost[1<<20+2],p[25];
void sol(){
cin>>n>>m;
for(int i=1; i<=n; i++) cin>>a[i],p[i]=p[i-1]+a[i];
for(int i=1; i<=m; i++) cin>>b[i];
for(int mask=0; mask<(1<<m); mask++) for(int i=0; i<m; i++) if((mask>>i)&1) cost[mask]+=b[i+1];
dp[0][0]=1;
for(int i=1; i<=n; i++){
for(int mask=1; mask<(1<<m); mask++){
if(cost[mask]!=p[i]) continue;
for(int mask2=mask; ; mask2=(mask2-1)&mask){
if(dp[i-1][mask2] and cost[mask^mask2]==a[i]){
dp[i][mask]=1;
break;
}
if(!mask2) break;
}
}
}
for(int i=1; i<(1<<m); i++){
if(dp[n][i]){
cout<<"YES";
return;
}
}
cout<<"NO";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
int tt=1;
//cin>>tt;
while(tt--){
sol();
}
cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
return 0;
}
/** /\_/\
* (= ._.)
* / >💖 \>💕
**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |