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 int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N=505;
int dp[N*500];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin>>n;
vector <int> a(n);
int sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}
dp[0]=1;
for(int i=0;i<n;i++){
for(int j=sum;j>=a[i];j--){
dp[j]+=dp[j-a[i]];
}
}
if(sum%2==1 or !dp[sum/2]){
cout<<0<<"\n";return 0;
}
map <int,int> mp;
for(int i=0;i<n;i++){
for(int j=a[i];j<=sum;j++){
dp[j]-=dp[j-a[i]];
}
for(int j=1;j<=sum-a[i];j++){
if(j*2>sum-a[i] && dp[j]){
mp[j*2-(sum-a[i])]++;
}
}
for(int j=sum;j>=a[i];j--){
dp[j]+=dp[j-a[i]];
}
}
vector <int> ans;
for(auto x : mp){
if(x.ss==n)ans.pb(x.ff);
}
cout<<ans.size()<<"\n";
for(auto x : ans)cout<<x<<" ";
cout<<'\n';
}
/*
4
1 3 1 5
6
3 5 7 11 9 13
3
2 2 2
4
200 200 200 200
4 25
1 2 3 4
1 2 3 4
12 6 3 4
3 3
19 4 5
2 6 2
5 60000
630510219 369411957 874325200 990002527 567203997
438920902 634940661 593780254 315929832 420627496
*/
# | 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... |