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 f0(i, n) for(int i=(0); i<n; i++)
#define f1(i, n) for(int i=(1); i<=n; i++)
using namespace std;
typedef long long ll;
const int N = 502;
int n, a[N], f[N*N], tmp[N*N], sum = 0, dd[N*N];
void add(int x){
for(int i = sum; i >= 0; i--){
f[i] += f[i - x];
}
}
void del(int x){
for(int i = 0; i <= sum; i++) tmp[i] = f[i];
for(int i = 0; i <= sum; i++){
if(i >= x)
tmp[i] -= tmp[i - x];
}
}
int main(){
ios_base::sync_with_stdio(0);
cin >> n;
f[0] = 1;
f1(i, n){
cin >> a[i], sum += a[i];
add(a[i]);
}
if(sum%2 || f[sum/2]==0){
return cout << 0 << endl, 0;
}
f1(i, n){
del(a[i]);
for(int j = sum; j >= 0; j--){
if(tmp[j] != 0){
int x = sum - 2*j - a[i];
if(x > 0) dd[x]++;
}
}
}
int cnt = 0;
for(int j = 0; j <= sum; j++) if(dd[j]==n) ++cnt;
cout << cnt << endl;
for(int j = 0; j <= sum; j++) if(dd[j]==n) cout << j << " ";
}
# | 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... |