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<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std;
const int N = 1e5 + 5;
typedef long long ll;
int n, a[505], sum;
vector<int> vec;
bitset<250005> b;
int ans[250005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum % 2 == 1) {
cout << 0;
return 0;
}
for (int i = 1; i <= sum; i++) {
ans[i] = 1;
}
for (int i = 0; i <= n; i++) {
b.reset();
b[0] = 1;
for (int j = 1; j <= n; j++) {
if (i != j)
b |= (b << a[j]);
}
if (i == 0) {
if (!b[sum / 2]) {
cout << 0;
return 0;
}
continue;
}
for (int j = 1; j <= sum; j++) {
if ((sum + j - a[i]) % 2) {
ans[j] = 0;
continue;
}
if (!b[(sum + j - a[i]) / 2]) {
ans[j] = 0;
}
}
}
int cnt = 0;
for (int i = 1; i <= sum; i++) {
cnt += ans[i];
}
cout << cnt << "\n";
for (int i = 1; i <= sum; i++)
if (ans[i])
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... |