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("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
long long dp[2*350*350+1];
long long mod = int(1e9+7);
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int arr[n] , sum = 0;
for(int i = 0;i<n;i++){
cin>>arr[i];sum+=arr[i];
}
dp[0] = 1;
for(int i = 0;i<n;i++){
for(int j = 2*sum;j>=arr[i];j--){
dp[j]+=dp[j-arr[i]];
if(dp[j]>=1e18)dp[j]%=mod;
}
}
if(sum%2||(!dp[sum/2])){
cout<<"0";
return 0;
}
vector<int> v;
for(int i = 1;i<=sum;i++){v.push_back(i);}
for(int it = 0;it<n;it++){
for(int j = arr[it];j<=2*sum;j++){
dp[j]-=dp[j-arr[it]];
dp[j]%=mod;dp[j]+=mod;dp[j]%=mod;
}
vector<int> c;
for(auto j:v){
if((sum-arr[it]+j)%2){
continue;
}
int ne = sum-arr[it]+j;
int d = (dp[ne/2]>0);
if(j<=ne/2)d|=(dp[(ne/2)-j]>0);
if(d==1)c.push_back(j);
}v = c;
for(int j = 2*sum;j>=arr[it];j--){
dp[j]+=dp[j-arr[it]];
if(dp[j]>=1e18)dp[j]%=mod;
}
}
cout<<v.size()<<"\n";
for(auto i:v)cout<<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... |