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;
#define f first
#define s second
const int N = 510;
const int A = 510;
bitset<250069> bt[N], sv;
int n, a[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
sv[0] = 1;
for (int i = 1;i <= n;i++)
cin >> a[i], sv |= (sv << a[i]);
int s = accumulate(a + 1, a + n + 1, 0);
if (s % 2 == 1 || sv[s / 2] == 0) {
cout << '0';
return 0;
}
s /= 2;
for (int j = 1;j <= n;j++) {
bitset<250069> t;
t[0] = 1;
for (int i = 1;i <= n;i++) {
if (i == j)
continue;
t |= (t << a[i]);
}
bt[j] = t;
}
vector<int> ans;
for (int i = (a[1] % 2 == 1 ? 1 : 2);i < N * A;i += 2) {
int ok = 1;
for (int j = 1;j <= n;j++) {
int r = i - a[j];
if (r & 1) {
ok = 0;
break;
}
r /= 2;
int x = s + r;
if (bt[j][x] == 0) {
ok = 0;
break;
}
}
if (ok)
ans.push_back(i);
}
cout << ans.size() << '\n';
for (auto i : ans)
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... |