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;
/*
written on phone :)))))
*/
const int N = 505;
long long dp[N*N];
int ans[N*N];
void add (int x) {
for (int i = N*N-1; i >= x; i--) {
dp[i] += dp[i-x];
}
}
void del (int x) {
for (int i = x; i < N*N; i++) {
dp[i] -= dp[i-x];
}
}
int main ()
{
dp[0] = 1;
int n; cin >> n;
vector <int> a (n);
bitset <N*N> d; d[0]=1;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
d |= (d << a[i]);
sum += a[i];
add(a[i]);
}
if (sum & 1) {
cout << 0; return 0;
}
if (!d[sum >> 1]) {
cout << 0; return 0;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
del(a[i]); sum-=a[i];
for (int j = sum&1; j <= N*N; j += 2) {
int need = ((sum+j)>>1)-j;
if (need >= 0 && dp[need] > 0) {
ans[j]++;
}
}
add(a[i]); sum+=a[i];
}
for (int i = 0; i < N*N;i++) {
if (ans[i] == n)
cnt++;
}
cout << cnt << endl;
for (int i = 0; i < N*N;i++) {
if (ans[i] == n)
cout << i << " ";
}
return 0;
}
# | 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... |