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 mod1=1e6+3,mod2=1e9+7;
int n,sum,a[505],C[250005],f1[250005],f2[250005];
vector<int> rs;
bool Special()
{
if(sum%2==1)
return false;
f1[0]=1;
f2[0]=1;
for(int i=1;i<=n;i++)
for(int j=sum;j>=a[i];j--)
{
f1[j]=(f1[j]+f1[j-a[i]])%mod1;
f2[j]=(f2[j]+f2[j-a[i]])%mod2;
}
return (f1[sum/2]>0||f2[sum/2]>0);
}
void Check(int pos)
{
for(int i=a[pos];i<=sum;i++)
{
f1[i]=(f1[i]-f1[i-a[pos]]+mod1)%mod1;
f2[i]=(f2[i]-f2[i-a[pos]]+mod2)%mod2;
}
for(int i=0;i<(sum-a[pos]+1)/2;i++)
if(f1[i]>0||f2[i]>0)
C[sum-a[pos]-2*i]++;
for(int i=sum;i>=a[pos];i--)
{
f1[i]=(f1[i]+f1[i-a[pos]])%mod1;
f2[i]=(f2[i]+f2[i-a[pos]])%mod2;
}
}
int main()
{
//freopen("TEST.INP","r",stdin);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
if(Special()==false)
{
cout<<0;
return 0;
}
for(int i=1;i<=n;i++)
Check(i);
for(int i=1;i<=sum;i++)
if(C[i]==n)
rs.push_back(i);
cout<<rs.size()<<"\n";
for(int i=0;i<rs.size();i++)
cout<<rs[i]<<' ';
}
Compilation message (stderr)
bootfall.cpp: In function 'int main()':
bootfall.cpp:60:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<rs.size();i++)
^
# | 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... |