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>
#define TASKNAME "bieudo"
#define pb push_back
#define pli pair<int,int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=600;
const ll mod=1e9+19972207;
ll dp[505*505];
ll cnt[505*505]={0};
ll n,a[maxN];
void solve()
{
cin >> n;
ll m=0;
for(int i=1;i<=n;i++) cin >> a[i],m+=a[i];
dp[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=m;j>=a[i];j--)
{
dp[j]+=dp[j-a[i]];
if(dp[j]>=mod) dp[j]-=mod;
//dp2[j]+=dp2[j-a[i]];
//if(dp2[j]>=mod2) dp2[j]-=mod2;
}
}
if(m%2!=0)
{
cout << 0;
return;
}
ll x=m/2;
if(dp[x]==0)
{
cout << 0;
return;
}
for(int i=1;i<=n;i++)
{
for(int j=a[i];j<=m;j++)
{
dp[j]-=dp[j-a[i]];
if(dp[j]<0) dp[j]+=mod;
}
for(int j=0;j<=(m-a[i])/2;j++)
{
if(dp[j]>0)
{
cnt[m-j-a[i]-j]++;
}
}
for(int j=m;j>=a[i];j--)
{
dp[j]+=dp[j-a[i]];
if(dp[j]>=mod) dp[j]-=mod;
}
}
vector<ll> ans;
for(int i=1;i<=m;i++)
{
if(cnt[i]==n)
{
ans.pb(i);
}
}
cout <<ans.size()<<'\n';
for(auto zz:ans) cout << zz <<' ';
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# | 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... |