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;
int n,tot;
int a[505];
bitset<500005> dp[505];
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];
tot+=a[i];
}
for(int i=1;i<=tot;i++)
variante[++cntv]=i;
dp[0][250000]=1;
for(int i=0;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)
dp[j] = dp[j-1];
else
dp[j] = ((dp[j-1]<<a[j])|(dp[j-1]>>a[j]));
}
if(i==0)
{
if(dp[n][250000]==0)
{
cntv=0;
break;
}
continue;
}
cntnew=0;
for(int j=1;j<=cntv;j++)
{
int x = variante[j];
if(dp[n][x+250000] || dp[n][-x+250000])
newv[++cntnew] = x;
///difs = -x
///difs = 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... |