Submission #995659

#TimeUsernameProblemLanguageResultExecution timeMemory
995659kokoueBank (IZhO14_bank)C++14
0 / 100
2 ms348 KiB
#include<bits/stdc++.h> #define maxn 21 using namespace std; int n,m; int dp[1<<maxn],sum[1<<maxn],pref[maxn],a[maxn],b[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=0;i<n;i++) { cin>>a[i]; if(i!=0) {pref[i]=pref[i-1]+a[i];continue;} pref[i]=a[i]; } for(int i=0;i<m;i++) { cin>>b[i]; } for(int i=1;i<(1<<m);i++) { for(int j=0;j<m;j++) { if(i&(1<<j)) sum[i]+=b[j]; } } for(int i=0;i<(1<<m);i++) { for(int j=0;j<m;j++) { if(!(i&(1<<j))) continue; int k=dp[i^(1<<j)]; int s; if(k==0) s==0; else s=pref[k-1]; if(sum[i]-s==a[k]) dp[i]=max(dp[i],dp[i^(1<<j)]+1); else dp[i]=max(dp[i],dp[i^(1<<j)]); } if(dp[i]==n) {cout<<i<<"\nYES\n";return 0;} } cout<<"NO\n"; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:36:23: warning: statement has no effect [-Wunused-value]
   36 |             if(k==0) s==0;
      |                      ~^~~
bank.cpp:38:22: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |             if(sum[i]-s==a[k]) dp[i]=max(dp[i],dp[i^(1<<j)]+1);
      |                ~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...