Submission #878250

#TimeUsernameProblemLanguageResultExecution timeMemory
878250alexddBootfall (IZhO17_bootfall)C++17
100 / 100
531 ms2132 KiB
#pragma GCC optimize("O3,unroll-loops") #include<iostream> #include<bitset> #include<algorithm> using namespace std; int n,tot; int a[505]; bitset<250005> dp; int variante[250005],cntv; int newv[250005],cntnew; signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; if(a[i]%2!=a[1]%2) { cout<<0; return 0; } tot+=a[i]; } if(tot%2==1) { cout<<0; return 0; } sort(a+1,a+1+n); for(int i=1;i<=tot;i++) if(i%2==a[1]%2) variante[++cntv]=i; for(int i=0;i<=n;i++) { if(i>1 && a[i]==a[i-1]) continue; 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(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...