Submission #878219

#TimeUsernameProblemLanguageResultExecution timeMemory
878219alexddBootfall (IZhO17_bootfall)C++17
44 / 100
1029 ms880 KiB
#include<bits/stdc++.h> using namespace std; int n,tot; int a[505]; bitset<500005> dp; int variante[500005],cntv; int newv[500005],cntnew; signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; tot+=a[i]; } if(tot%2==1) { cout<<0; return 0; } for(int i=1;i<=tot;i++) if(i%2==a[1]%2) variante[++cntv]=i; for(int i=0;i<=n;i++) { dp.reset(); dp[0]=1; for(int j=1;j<=n;j++) { if(i!=j) dp |= (dp<<a[j]); } if(i==0) { if(dp[tot/2]==0) { cout<<0; return 0; } continue; } cntnew=0; for(int j=1;j<=cntv;j++) { int x = variante[j]; if((tot-a[i]+x)%2==0 && dp[(tot-a[i]+x)/2]) newv[++cntnew] = x; ///tot - a[i] + x } cntv=cntnew; for(int j=1;j<=cntnew;j++) variante[j] = newv[j]; } cout<<cntv<<"\n"; for(int i=1;i<=cntv;i++) cout<<variante[i]<<" "; return 0; } /** 3 2 2 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...