# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36156 | Dat160601 | Bootfall (IZhO17_bootfall) | C++14 | 526 ms | 5800 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |