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>
using namespace std;
int a[501], f[250001], ans[250001], Ans, t;
int main(){
int n, s = 0; cin >> n;
f[0] = 1;
ans[0] = n + 1;
for(int i = 1; i <= n; i ++){
cin >> a[i];
for(int j = s; j >= 0; j --)
f[j + a[i]] += f[j];
s += a[i];
}
for(int i = 1; i <= n; i ++){
s -= a[i];
for(int j = 0; j <= s; j ++){
f[j + a[i]] -= f[j];
ans[max(j + j - s, 0)] += (!!f[j]);
Ans += (ans[max(j + j - s, 0)] == n);
}
for(int j = s; j >= 0; j --){
f[j + a[i]] += f[j];
s += a[i];
}
}
if(s & 1 || !f[s / 2]){
cout << 0; return 0;
}
cout << Ans << '\n';
for(int i = 1; i <= s; i ++)
if(ans[i] == n)
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... |