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;
const int maxn = 503;
bitset <250006> ans;
bitset <250006> tek;
bitset <250006> newtek;
int i,j,p,q,n,m,k,sum;
int a[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(i=1; i<=n; i++)
{
cin>>a[i];
sum+=a[i];
}
if(sum%2!=0)
{
cout<<0<<endl;
return 0;
}
for(i=2;i<=n;i++)
{
if(a[i]%2!=a[i-1]%2)
{
cout<<0<<endl;
return 0;
}
}
bitset <250006> tek;
tek.set(0);
tek[0]=true;
for(i=1;i<=n;i++)
{
tek|=(tek<<a[i]);
}
if(!tek[sum/2])
{
cout<<0<<endl;
return 0;
}
for(i=1;i<sum;i++)
ans[i]=1;
tek.set(false);
for(i=1;i<=n;i++)
{
///bez i
bitset <250006> tek;
tek[0]=1;
for(j=1;j<=n;j++)
{
if(j==i)continue;
tek|=(tek<<(2*a[j]));
}
tek=(tek<<(a[i]));
tek[0]=1;
ans&=tek;
}
int br = 0;
for(i=1;i<sum;i++)
if(ans[i])br++;
cout<<br<<endl;
for(i=sum-1;i>=1;i--)
{
if(ans[i])
cout<<sum-i<<" ";
}
return 0;
}
/**
4
1 3 1 5
4
200 200 200 200
*/
# | 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... |