#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define boost ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const int inf = INT_MAX;
const int mod = 998244353;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int N = 505;
const int M = 1e2+1;
int a[N],p[N*N],sum,b[N*N],cnt[N*N];
void add(int x){
for(int i=sum;i>=0;i--){
p[i]+=p[i-x];
}
}
void del(int x){
for(int i=0;i<=sum;i++)b[i]=p[i];
for(int i=0;i<=sum;i++){
if(i>=x)b[i]-=b[i-x];
}
}
int main(){
int n;
cin>>n;
p[0]=1;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
add(a[i]);
}
if(sum%2||p[sum/2]==0){
cout<<0;
return 0;
}
for(int i=1;i<=n;i++){
del(a[i]);
for(int j=sum;j>=0;j--){
if(b[j]){
int val=sum-2*j-a[i];
//cout<<val<<" ";
if(val>0)cnt[val]++;
}
}
}
vector<int>ans;
for(int i=0;i<=sum;i++){
if(cnt[i]==n)ans.pb(i);
}
cout<<sz(ans)<<endl;
for(int i=0;i<sz(ans);i++){
cout<<ans[i]<<" ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |