This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O2,unroll-loops")
#include<iostream>
#include<bitset>
using namespace std;
int n,tot;
int a[505];
bitset<500005> dp;
int variante[500005],cntv;
int newv[500005],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;
}
for(int i=1;i<=tot;i++)
if(i%2==a[1]%2)
variante[++cntv]=i;
for(int i=0;i<=n;i++)
{
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((tot-a[i]+x)%2==0 && 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 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... |