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 maxn 510
using namespace std;
int n, a[maxn], kS[maxn*maxn], isOk[maxn*maxn], ans, sum;
int main(){
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i){
cin >> a[i];
sum += a[i];
}
kS[0] = 1;
for(int i = 0; i < n; ++i){
for(int j = sum-a[i]; j >= 0; --j){
kS[j+a[i]] += kS[j];
}
}if(sum%2 or !kS[sum/2]){
cout <<0;
return 0;
}
for(int i = 0; i < n; ++i){
int tmp = sum-a[i];
for(int j = a[i]; j <= sum; ++j){
kS[j] -= kS[j-a[i]];
//cerr << kS[j] << ' ';
if(2*j - tmp > 0 and kS[j]){
isOk[2*j - tmp]++;
if(isOk[-tmp+j*2] == n){
++ans;
}
}
}
for(int j = 1; j < a[i]; ++j){
if(2*j - tmp > 0 and kS[j]){
isOk[2*j - tmp]++;
if(isOk[-tmp+j*2] == n){
++ans;
}
}
}
cerr << '\n';
for(int j = sum-a[i]; j >= 0; --j){
kS[j+a[i]] += kS[j];
}
}
cout << ans << '\n';
for(int i = 1; i <= sum; ++i){
if(isOk[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... |