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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 505, M = 250005;
int n;
int a[N];
bitset<M / 2> dp;
bitset<M> res, tmp;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
res = bitset<M>().set();
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 0; i <= n; ++i) {
dp.reset();
dp.set(0);
int sum = 0;
for (int j = 1; j <= n; ++j) {
if (i ^ j) {
dp |= dp << a[j];
sum += a[j];
}
}
if (!i && !dp.test(sum / 2)) {
cout << 0 << "\n";
exit(0);
}
tmp.reset();
if (i) {
for (int ii = 0; ii <= sum / 2; ++ii) {
if (dp.test(ii)) {
tmp.set(sum - 2 * ii);
}
}
res &= tmp;
}
}
cout << res.count() << "\n";
for (int i = 0; i < M; ++i) {
if (res.test(i)) {
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... |