#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
const int maxc = 20000;
int S;
bitset<maxc> ans, q;
vector<int> a;
void solve(int l,int r,bitset<maxc> b) {
if (l == r) {
q.reset();
for (int j = 0; j < maxc; ++j) {
int needsum = (S - 2 * j - a[l]);
if (needsum < 0) continue;
if (b[j]) {
q[needsum] = 1;
}
}
ans &= q;
return;
}
int m = (l + r) >> 1;
bitset<maxc> l1, r1;
l1 = b;
r1 = b;
for (int i = l; i <= m; ++i) {
l1 |= l1 << a[i];
}
for (int i = m + 1; i <= r; ++i) {
r1 |= r1 << a[i];
}
solve(l, m, r1);
solve(m + 1, r, l1);
}
int main() {
int n;
cin >> n;
a.resize(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
S += a[i];
}
for (int i = 0; i < maxc; ++i) ans[i] = 1;
bitset<maxc> cur;
cur[0] = 1;
solve(0, n - 1, cur);
for (int i = 0; i < n; ++i) {
cur |= cur << a[i];
}
if (S % 2 || !cur[S / 2]) {
cout << 0;
return 0;
}
vector<int> answer;
for (int i = 1; i < maxc; ++i) {
if (ans[i]) answer.push_back(i);
}
cout << answer.size() << '\n';
for (auto elem : answer) cout << elem << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
5 ms |
444 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
4 ms |
492 KB |
Output is correct |
29 |
Correct |
4 ms |
364 KB |
Output is correct |
30 |
Correct |
4 ms |
364 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
4 ms |
492 KB |
Output is correct |
33 |
Correct |
5 ms |
364 KB |
Output is correct |
34 |
Correct |
5 ms |
364 KB |
Output is correct |
35 |
Correct |
4 ms |
364 KB |
Output is correct |
36 |
Correct |
6 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
5 ms |
444 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
4 ms |
492 KB |
Output is correct |
29 |
Correct |
4 ms |
364 KB |
Output is correct |
30 |
Correct |
4 ms |
364 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
4 ms |
492 KB |
Output is correct |
33 |
Correct |
5 ms |
364 KB |
Output is correct |
34 |
Correct |
5 ms |
364 KB |
Output is correct |
35 |
Correct |
4 ms |
364 KB |
Output is correct |
36 |
Correct |
6 ms |
492 KB |
Output is correct |
37 |
Correct |
12 ms |
620 KB |
Output is correct |
38 |
Correct |
10 ms |
620 KB |
Output is correct |
39 |
Incorrect |
10 ms |
364 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
5 ms |
444 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
4 ms |
492 KB |
Output is correct |
29 |
Correct |
4 ms |
364 KB |
Output is correct |
30 |
Correct |
4 ms |
364 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
4 ms |
492 KB |
Output is correct |
33 |
Correct |
5 ms |
364 KB |
Output is correct |
34 |
Correct |
5 ms |
364 KB |
Output is correct |
35 |
Correct |
4 ms |
364 KB |
Output is correct |
36 |
Correct |
6 ms |
492 KB |
Output is correct |
37 |
Correct |
12 ms |
620 KB |
Output is correct |
38 |
Correct |
10 ms |
620 KB |
Output is correct |
39 |
Incorrect |
10 ms |
364 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
5 ms |
444 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
4 ms |
492 KB |
Output is correct |
29 |
Correct |
4 ms |
364 KB |
Output is correct |
30 |
Correct |
4 ms |
364 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
4 ms |
492 KB |
Output is correct |
33 |
Correct |
5 ms |
364 KB |
Output is correct |
34 |
Correct |
5 ms |
364 KB |
Output is correct |
35 |
Correct |
4 ms |
364 KB |
Output is correct |
36 |
Correct |
6 ms |
492 KB |
Output is correct |
37 |
Correct |
12 ms |
620 KB |
Output is correct |
38 |
Correct |
10 ms |
620 KB |
Output is correct |
39 |
Incorrect |
10 ms |
364 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |