#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
const int maxc = 500 * 500 + 10;
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 << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
1004 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
1004 KB |
Output is correct |
8 |
Correct |
8 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
1004 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
1004 KB |
Output is correct |
8 |
Correct |
8 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1132 KB |
Output is correct |
10 |
Correct |
12 ms |
1260 KB |
Output is correct |
11 |
Correct |
12 ms |
1260 KB |
Output is correct |
12 |
Correct |
15 ms |
1260 KB |
Output is correct |
13 |
Correct |
10 ms |
1260 KB |
Output is correct |
14 |
Correct |
11 ms |
1260 KB |
Output is correct |
15 |
Correct |
11 ms |
1408 KB |
Output is correct |
16 |
Correct |
12 ms |
1260 KB |
Output is correct |
17 |
Correct |
8 ms |
1260 KB |
Output is correct |
18 |
Correct |
10 ms |
1260 KB |
Output is correct |
19 |
Correct |
10 ms |
1260 KB |
Output is correct |
20 |
Correct |
12 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
1004 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
1004 KB |
Output is correct |
8 |
Correct |
8 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1132 KB |
Output is correct |
10 |
Correct |
12 ms |
1260 KB |
Output is correct |
11 |
Correct |
12 ms |
1260 KB |
Output is correct |
12 |
Correct |
15 ms |
1260 KB |
Output is correct |
13 |
Correct |
10 ms |
1260 KB |
Output is correct |
14 |
Correct |
11 ms |
1260 KB |
Output is correct |
15 |
Correct |
11 ms |
1408 KB |
Output is correct |
16 |
Correct |
12 ms |
1260 KB |
Output is correct |
17 |
Correct |
8 ms |
1260 KB |
Output is correct |
18 |
Correct |
10 ms |
1260 KB |
Output is correct |
19 |
Correct |
10 ms |
1260 KB |
Output is correct |
20 |
Correct |
12 ms |
1260 KB |
Output is correct |
21 |
Correct |
25 ms |
1388 KB |
Output is correct |
22 |
Correct |
34 ms |
1644 KB |
Output is correct |
23 |
Correct |
18 ms |
1388 KB |
Output is correct |
24 |
Correct |
33 ms |
1644 KB |
Output is correct |
25 |
Correct |
34 ms |
1644 KB |
Output is correct |
26 |
Correct |
43 ms |
1644 KB |
Output is correct |
27 |
Correct |
35 ms |
1644 KB |
Output is correct |
28 |
Correct |
40 ms |
1644 KB |
Output is correct |
29 |
Correct |
36 ms |
1516 KB |
Output is correct |
30 |
Correct |
35 ms |
1516 KB |
Output is correct |
31 |
Correct |
36 ms |
1644 KB |
Output is correct |
32 |
Correct |
35 ms |
1644 KB |
Output is correct |
33 |
Correct |
35 ms |
1516 KB |
Output is correct |
34 |
Correct |
35 ms |
1516 KB |
Output is correct |
35 |
Correct |
35 ms |
1516 KB |
Output is correct |
36 |
Correct |
36 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
1004 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
1004 KB |
Output is correct |
8 |
Correct |
8 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1132 KB |
Output is correct |
10 |
Correct |
12 ms |
1260 KB |
Output is correct |
11 |
Correct |
12 ms |
1260 KB |
Output is correct |
12 |
Correct |
15 ms |
1260 KB |
Output is correct |
13 |
Correct |
10 ms |
1260 KB |
Output is correct |
14 |
Correct |
11 ms |
1260 KB |
Output is correct |
15 |
Correct |
11 ms |
1408 KB |
Output is correct |
16 |
Correct |
12 ms |
1260 KB |
Output is correct |
17 |
Correct |
8 ms |
1260 KB |
Output is correct |
18 |
Correct |
10 ms |
1260 KB |
Output is correct |
19 |
Correct |
10 ms |
1260 KB |
Output is correct |
20 |
Correct |
12 ms |
1260 KB |
Output is correct |
21 |
Correct |
25 ms |
1388 KB |
Output is correct |
22 |
Correct |
34 ms |
1644 KB |
Output is correct |
23 |
Correct |
18 ms |
1388 KB |
Output is correct |
24 |
Correct |
33 ms |
1644 KB |
Output is correct |
25 |
Correct |
34 ms |
1644 KB |
Output is correct |
26 |
Correct |
43 ms |
1644 KB |
Output is correct |
27 |
Correct |
35 ms |
1644 KB |
Output is correct |
28 |
Correct |
40 ms |
1644 KB |
Output is correct |
29 |
Correct |
36 ms |
1516 KB |
Output is correct |
30 |
Correct |
35 ms |
1516 KB |
Output is correct |
31 |
Correct |
36 ms |
1644 KB |
Output is correct |
32 |
Correct |
35 ms |
1644 KB |
Output is correct |
33 |
Correct |
35 ms |
1516 KB |
Output is correct |
34 |
Correct |
35 ms |
1516 KB |
Output is correct |
35 |
Correct |
35 ms |
1516 KB |
Output is correct |
36 |
Correct |
36 ms |
1644 KB |
Output is correct |
37 |
Correct |
78 ms |
1900 KB |
Output is correct |
38 |
Correct |
75 ms |
1900 KB |
Output is correct |
39 |
Correct |
89 ms |
1772 KB |
Output is correct |
40 |
Correct |
109 ms |
2156 KB |
Output is correct |
41 |
Correct |
97 ms |
1948 KB |
Output is correct |
42 |
Correct |
94 ms |
1900 KB |
Output is correct |
43 |
Correct |
99 ms |
2156 KB |
Output is correct |
44 |
Correct |
104 ms |
2156 KB |
Output is correct |
45 |
Correct |
101 ms |
2156 KB |
Output is correct |
46 |
Correct |
96 ms |
2028 KB |
Output is correct |
47 |
Correct |
122 ms |
2028 KB |
Output is correct |
48 |
Correct |
119 ms |
2028 KB |
Output is correct |
49 |
Correct |
92 ms |
1900 KB |
Output is correct |
50 |
Correct |
94 ms |
1900 KB |
Output is correct |
51 |
Correct |
91 ms |
1772 KB |
Output is correct |
52 |
Correct |
110 ms |
2284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
1004 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
1004 KB |
Output is correct |
8 |
Correct |
8 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1132 KB |
Output is correct |
10 |
Correct |
12 ms |
1260 KB |
Output is correct |
11 |
Correct |
12 ms |
1260 KB |
Output is correct |
12 |
Correct |
15 ms |
1260 KB |
Output is correct |
13 |
Correct |
10 ms |
1260 KB |
Output is correct |
14 |
Correct |
11 ms |
1260 KB |
Output is correct |
15 |
Correct |
11 ms |
1408 KB |
Output is correct |
16 |
Correct |
12 ms |
1260 KB |
Output is correct |
17 |
Correct |
8 ms |
1260 KB |
Output is correct |
18 |
Correct |
10 ms |
1260 KB |
Output is correct |
19 |
Correct |
10 ms |
1260 KB |
Output is correct |
20 |
Correct |
12 ms |
1260 KB |
Output is correct |
21 |
Correct |
25 ms |
1388 KB |
Output is correct |
22 |
Correct |
34 ms |
1644 KB |
Output is correct |
23 |
Correct |
18 ms |
1388 KB |
Output is correct |
24 |
Correct |
33 ms |
1644 KB |
Output is correct |
25 |
Correct |
34 ms |
1644 KB |
Output is correct |
26 |
Correct |
43 ms |
1644 KB |
Output is correct |
27 |
Correct |
35 ms |
1644 KB |
Output is correct |
28 |
Correct |
40 ms |
1644 KB |
Output is correct |
29 |
Correct |
36 ms |
1516 KB |
Output is correct |
30 |
Correct |
35 ms |
1516 KB |
Output is correct |
31 |
Correct |
36 ms |
1644 KB |
Output is correct |
32 |
Correct |
35 ms |
1644 KB |
Output is correct |
33 |
Correct |
35 ms |
1516 KB |
Output is correct |
34 |
Correct |
35 ms |
1516 KB |
Output is correct |
35 |
Correct |
35 ms |
1516 KB |
Output is correct |
36 |
Correct |
36 ms |
1644 KB |
Output is correct |
37 |
Correct |
78 ms |
1900 KB |
Output is correct |
38 |
Correct |
75 ms |
1900 KB |
Output is correct |
39 |
Correct |
89 ms |
1772 KB |
Output is correct |
40 |
Correct |
109 ms |
2156 KB |
Output is correct |
41 |
Correct |
97 ms |
1948 KB |
Output is correct |
42 |
Correct |
94 ms |
1900 KB |
Output is correct |
43 |
Correct |
99 ms |
2156 KB |
Output is correct |
44 |
Correct |
104 ms |
2156 KB |
Output is correct |
45 |
Correct |
101 ms |
2156 KB |
Output is correct |
46 |
Correct |
96 ms |
2028 KB |
Output is correct |
47 |
Correct |
122 ms |
2028 KB |
Output is correct |
48 |
Correct |
119 ms |
2028 KB |
Output is correct |
49 |
Correct |
92 ms |
1900 KB |
Output is correct |
50 |
Correct |
94 ms |
1900 KB |
Output is correct |
51 |
Correct |
91 ms |
1772 KB |
Output is correct |
52 |
Correct |
110 ms |
2284 KB |
Output is correct |
53 |
Correct |
132 ms |
2308 KB |
Output is correct |
54 |
Correct |
142 ms |
2284 KB |
Output is correct |
55 |
Correct |
169 ms |
2516 KB |
Output is correct |
56 |
Correct |
123 ms |
2284 KB |
Output is correct |
57 |
Correct |
158 ms |
2536 KB |
Output is correct |
58 |
Correct |
143 ms |
2264 KB |
Output is correct |
59 |
Correct |
149 ms |
2408 KB |
Output is correct |
60 |
Correct |
140 ms |
1900 KB |
Output is correct |
61 |
Correct |
149 ms |
2408 KB |
Output is correct |
62 |
Correct |
139 ms |
2408 KB |
Output is correct |
63 |
Correct |
141 ms |
2536 KB |
Output is correct |
64 |
Correct |
141 ms |
2536 KB |
Output is correct |
65 |
Correct |
117 ms |
1900 KB |
Output is correct |
66 |
Correct |
110 ms |
2008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
1004 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
1004 KB |
Output is correct |
8 |
Correct |
8 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1132 KB |
Output is correct |
10 |
Correct |
12 ms |
1260 KB |
Output is correct |
11 |
Correct |
12 ms |
1260 KB |
Output is correct |
12 |
Correct |
15 ms |
1260 KB |
Output is correct |
13 |
Correct |
10 ms |
1260 KB |
Output is correct |
14 |
Correct |
11 ms |
1260 KB |
Output is correct |
15 |
Correct |
11 ms |
1408 KB |
Output is correct |
16 |
Correct |
12 ms |
1260 KB |
Output is correct |
17 |
Correct |
8 ms |
1260 KB |
Output is correct |
18 |
Correct |
10 ms |
1260 KB |
Output is correct |
19 |
Correct |
10 ms |
1260 KB |
Output is correct |
20 |
Correct |
12 ms |
1260 KB |
Output is correct |
21 |
Correct |
25 ms |
1388 KB |
Output is correct |
22 |
Correct |
34 ms |
1644 KB |
Output is correct |
23 |
Correct |
18 ms |
1388 KB |
Output is correct |
24 |
Correct |
33 ms |
1644 KB |
Output is correct |
25 |
Correct |
34 ms |
1644 KB |
Output is correct |
26 |
Correct |
43 ms |
1644 KB |
Output is correct |
27 |
Correct |
35 ms |
1644 KB |
Output is correct |
28 |
Correct |
40 ms |
1644 KB |
Output is correct |
29 |
Correct |
36 ms |
1516 KB |
Output is correct |
30 |
Correct |
35 ms |
1516 KB |
Output is correct |
31 |
Correct |
36 ms |
1644 KB |
Output is correct |
32 |
Correct |
35 ms |
1644 KB |
Output is correct |
33 |
Correct |
35 ms |
1516 KB |
Output is correct |
34 |
Correct |
35 ms |
1516 KB |
Output is correct |
35 |
Correct |
35 ms |
1516 KB |
Output is correct |
36 |
Correct |
36 ms |
1644 KB |
Output is correct |
37 |
Correct |
78 ms |
1900 KB |
Output is correct |
38 |
Correct |
75 ms |
1900 KB |
Output is correct |
39 |
Correct |
89 ms |
1772 KB |
Output is correct |
40 |
Correct |
109 ms |
2156 KB |
Output is correct |
41 |
Correct |
97 ms |
1948 KB |
Output is correct |
42 |
Correct |
94 ms |
1900 KB |
Output is correct |
43 |
Correct |
99 ms |
2156 KB |
Output is correct |
44 |
Correct |
104 ms |
2156 KB |
Output is correct |
45 |
Correct |
101 ms |
2156 KB |
Output is correct |
46 |
Correct |
96 ms |
2028 KB |
Output is correct |
47 |
Correct |
122 ms |
2028 KB |
Output is correct |
48 |
Correct |
119 ms |
2028 KB |
Output is correct |
49 |
Correct |
92 ms |
1900 KB |
Output is correct |
50 |
Correct |
94 ms |
1900 KB |
Output is correct |
51 |
Correct |
91 ms |
1772 KB |
Output is correct |
52 |
Correct |
110 ms |
2284 KB |
Output is correct |
53 |
Correct |
132 ms |
2308 KB |
Output is correct |
54 |
Correct |
142 ms |
2284 KB |
Output is correct |
55 |
Correct |
169 ms |
2516 KB |
Output is correct |
56 |
Correct |
123 ms |
2284 KB |
Output is correct |
57 |
Correct |
158 ms |
2536 KB |
Output is correct |
58 |
Correct |
143 ms |
2264 KB |
Output is correct |
59 |
Correct |
149 ms |
2408 KB |
Output is correct |
60 |
Correct |
140 ms |
1900 KB |
Output is correct |
61 |
Correct |
149 ms |
2408 KB |
Output is correct |
62 |
Correct |
139 ms |
2408 KB |
Output is correct |
63 |
Correct |
141 ms |
2536 KB |
Output is correct |
64 |
Correct |
141 ms |
2536 KB |
Output is correct |
65 |
Correct |
117 ms |
1900 KB |
Output is correct |
66 |
Correct |
110 ms |
2008 KB |
Output is correct |
67 |
Correct |
169 ms |
2408 KB |
Output is correct |
68 |
Correct |
185 ms |
1900 KB |
Output is correct |
69 |
Correct |
267 ms |
3044 KB |
Output is correct |
70 |
Correct |
231 ms |
2664 KB |
Output is correct |
71 |
Correct |
228 ms |
2664 KB |
Output is correct |
72 |
Correct |
221 ms |
1900 KB |
Output is correct |
73 |
Correct |
221 ms |
2028 KB |
Output is correct |
74 |
Correct |
285 ms |
3172 KB |
Output is correct |
75 |
Correct |
256 ms |
2916 KB |
Output is correct |
76 |
Correct |
275 ms |
3044 KB |
Output is correct |
77 |
Correct |
271 ms |
3172 KB |
Output is correct |