Submission #1001390

#TimeUsernameProblemLanguageResultExecution timeMemory
1001390cnn008Bank (IZhO14_bank)C++17
100 / 100
405 ms193400 KiB
#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)

bank.cpp:55:9: warning: "/*" within comment [-Wcomment]
   55 | /**  /\_/\
      |          
bank.cpp:15:33: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   15 | int n,m,a[25],b[25],dp[25][1<<20+2],cost[1<<20+2],p[25];
      |                               ~~^~
bank.cpp:15:47: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   15 | int n,m,a[25],b[25],dp[25][1<<20+2],cost[1<<20+2],p[25];
      |                                             ~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...