Submission #36156

#TimeUsernameProblemLanguageResultExecution timeMemory
36156Dat160601Bootfall (IZhO17_bootfall)C++14
100 / 100
526 ms5800 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back vector <int> ans; int n,a[507],sum[507],dp[250007],save[250007],res[250007]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); sum[i]=sum[i-1]+a[i]; } if(sum[n]%2==1){ printf("0"); return 0; } save[0]=1; save[a[1]]=1; for(int i=2;i<=n;i++){ for(int j=0;j<=sum[i];j++){ if(j<a[i]) dp[j]=save[j]; else dp[j]=save[j]+save[j-a[i]]; } for(int j=0;j<=sum[i];j++) save[j]=dp[j]; } if(dp[sum[n]/2]==0){ printf("0"); return 0; } for(int i=1;i<=n;i++){ for(int j=0;j<=sum[n];j++) save[j]=dp[j]; for(int j=0;j<=sum[n];j++){ if(j>=a[i]) save[j]-=save[j-a[i]]; } for(int j=sum[n];j>=1;j--){ int val=sum[n]+j-a[i]; if(val%2==1 || save[val/2]==0) continue; res[j]++; } } for(int j=1;j<=sum[n];j++){ if(res[j]==n) ans.pb(j); } printf("%d\n",(int)ans.size()); for(int i=0;i<(int)ans.size();i++) printf("%d ",ans[i]); }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:7:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
bootfall.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
#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...