#include <bits/stdc++.h>
using namespace std;
long long dp[500*500+1];
long long ee[500*500+1];
long long mod = int(1e9+7);
bitset<500*500+1> su;
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 = 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;
}
for(int i = (arr[0]%2?1:2);i<=sum;i+=2){su[i] = 1;}
for(int it = 0;it<n;it++){
for(int j = 0;j<=sum;j++){
ee[j] = dp[j];
if(j>=arr[it]){
ee[j]-=ee[j-arr[it]];
ee[j]%=mod;
if(ee[j]<0){ee[j]%=mod;ee[j]+=mod;ee[j]%=mod;}
}
if((sum-arr[it]+j)%2){
su[j] = 0;
continue;
}
int ne = sum-arr[it]+j;
int d = 0;
if(ne/2<=sum)d = (ee[ne/2]>0);
else break;
if(j<=ne/2&&(ne/2)-j<=sum)d|=(ee[(ne/2)-j]>0);
if(d==0)su[j] = 0;
}
}
cout<<su.count()<<"\n";
for(int i = 1;i<=sum;i++)if(su[i])cout<<i<<" ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |