# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548776 | krit3379 | Bootfall (IZhO17_bootfall) | C++17 | 144 ms | 4108 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 N 251000
int a[505],cnt[N],odd,even,sum;
vector<int> ans;
bitset<N> dp;
void sol(int l,int r,bitset<N> cur){
if(l==r){
for(int i=odd?1:2,val=sum-a[l];i<N;i+=2){
if(val-i>=0&&cur[(val-i)/2])cnt[i]++;
}
return ;
}
int mid=(l+r)/2;
bitset<N> dl=cur,dr=cur;
for(int i=l;i<=mid;i++)dr|=dr<<a[i];
for(int i=mid+1;i<=r;i++)dl|=dl<<a[i];
sol(l,mid,dl),sol(mid+1,r,dr);
}
int main(){
int n,i;
scanf("%d",&n);
dp=1;
for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i],(a[i]%2)?odd++:even++,dp|=dp<<a[i];
if((odd&&even)||(odd&&n%2)||!dp[sum/2]){printf("0");return 0;}
dp=1;
sol(1,n,dp);
for(i=1;i<N;i++)if(cnt[i]==n)ans.push_back(i);
printf("%d\n",ans.size());
for(auto x:ans)printf("%d ",x);
return 0;
}
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... |