#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
580 KB |
Output is correct |
12 |
Correct |
4 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
580 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
580 KB |
Output is correct |
12 |
Correct |
4 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
580 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
13 ms |
344 KB |
Output is correct |
22 |
Correct |
18 ms |
348 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
36 ms |
348 KB |
Output is correct |
25 |
Correct |
29 ms |
572 KB |
Output is correct |
26 |
Correct |
34 ms |
572 KB |
Output is correct |
27 |
Correct |
39 ms |
564 KB |
Output is correct |
28 |
Correct |
33 ms |
348 KB |
Output is correct |
29 |
Correct |
33 ms |
348 KB |
Output is correct |
30 |
Correct |
39 ms |
348 KB |
Output is correct |
31 |
Correct |
32 ms |
348 KB |
Output is correct |
32 |
Correct |
32 ms |
348 KB |
Output is correct |
33 |
Correct |
35 ms |
348 KB |
Output is correct |
34 |
Correct |
32 ms |
348 KB |
Output is correct |
35 |
Correct |
32 ms |
348 KB |
Output is correct |
36 |
Correct |
43 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
580 KB |
Output is correct |
12 |
Correct |
4 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
580 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
13 ms |
344 KB |
Output is correct |
22 |
Correct |
18 ms |
348 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
36 ms |
348 KB |
Output is correct |
25 |
Correct |
29 ms |
572 KB |
Output is correct |
26 |
Correct |
34 ms |
572 KB |
Output is correct |
27 |
Correct |
39 ms |
564 KB |
Output is correct |
28 |
Correct |
33 ms |
348 KB |
Output is correct |
29 |
Correct |
33 ms |
348 KB |
Output is correct |
30 |
Correct |
39 ms |
348 KB |
Output is correct |
31 |
Correct |
32 ms |
348 KB |
Output is correct |
32 |
Correct |
32 ms |
348 KB |
Output is correct |
33 |
Correct |
35 ms |
348 KB |
Output is correct |
34 |
Correct |
32 ms |
348 KB |
Output is correct |
35 |
Correct |
32 ms |
348 KB |
Output is correct |
36 |
Correct |
43 ms |
348 KB |
Output is correct |
37 |
Correct |
128 ms |
568 KB |
Output is correct |
38 |
Correct |
128 ms |
596 KB |
Output is correct |
39 |
Correct |
197 ms |
348 KB |
Output is correct |
40 |
Correct |
241 ms |
568 KB |
Output is correct |
41 |
Correct |
233 ms |
344 KB |
Output is correct |
42 |
Correct |
198 ms |
592 KB |
Output is correct |
43 |
Correct |
195 ms |
568 KB |
Output is correct |
44 |
Correct |
209 ms |
596 KB |
Output is correct |
45 |
Correct |
209 ms |
556 KB |
Output is correct |
46 |
Correct |
227 ms |
348 KB |
Output is correct |
47 |
Correct |
211 ms |
592 KB |
Output is correct |
48 |
Correct |
216 ms |
548 KB |
Output is correct |
49 |
Correct |
209 ms |
604 KB |
Output is correct |
50 |
Correct |
219 ms |
592 KB |
Output is correct |
51 |
Correct |
202 ms |
348 KB |
Output is correct |
52 |
Correct |
264 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
580 KB |
Output is correct |
12 |
Correct |
4 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
580 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
13 ms |
344 KB |
Output is correct |
22 |
Correct |
18 ms |
348 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
36 ms |
348 KB |
Output is correct |
25 |
Correct |
29 ms |
572 KB |
Output is correct |
26 |
Correct |
34 ms |
572 KB |
Output is correct |
27 |
Correct |
39 ms |
564 KB |
Output is correct |
28 |
Correct |
33 ms |
348 KB |
Output is correct |
29 |
Correct |
33 ms |
348 KB |
Output is correct |
30 |
Correct |
39 ms |
348 KB |
Output is correct |
31 |
Correct |
32 ms |
348 KB |
Output is correct |
32 |
Correct |
32 ms |
348 KB |
Output is correct |
33 |
Correct |
35 ms |
348 KB |
Output is correct |
34 |
Correct |
32 ms |
348 KB |
Output is correct |
35 |
Correct |
32 ms |
348 KB |
Output is correct |
36 |
Correct |
43 ms |
348 KB |
Output is correct |
37 |
Correct |
128 ms |
568 KB |
Output is correct |
38 |
Correct |
128 ms |
596 KB |
Output is correct |
39 |
Correct |
197 ms |
348 KB |
Output is correct |
40 |
Correct |
241 ms |
568 KB |
Output is correct |
41 |
Correct |
233 ms |
344 KB |
Output is correct |
42 |
Correct |
198 ms |
592 KB |
Output is correct |
43 |
Correct |
195 ms |
568 KB |
Output is correct |
44 |
Correct |
209 ms |
596 KB |
Output is correct |
45 |
Correct |
209 ms |
556 KB |
Output is correct |
46 |
Correct |
227 ms |
348 KB |
Output is correct |
47 |
Correct |
211 ms |
592 KB |
Output is correct |
48 |
Correct |
216 ms |
548 KB |
Output is correct |
49 |
Correct |
209 ms |
604 KB |
Output is correct |
50 |
Correct |
219 ms |
592 KB |
Output is correct |
51 |
Correct |
202 ms |
348 KB |
Output is correct |
52 |
Correct |
264 ms |
556 KB |
Output is correct |
53 |
Correct |
302 ms |
608 KB |
Output is correct |
54 |
Correct |
405 ms |
592 KB |
Output is correct |
55 |
Correct |
456 ms |
820 KB |
Output is correct |
56 |
Correct |
308 ms |
596 KB |
Output is correct |
57 |
Correct |
424 ms |
848 KB |
Output is correct |
58 |
Correct |
399 ms |
556 KB |
Output is correct |
59 |
Correct |
409 ms |
552 KB |
Output is correct |
60 |
Correct |
398 ms |
348 KB |
Output is correct |
61 |
Correct |
416 ms |
564 KB |
Output is correct |
62 |
Correct |
349 ms |
592 KB |
Output is correct |
63 |
Correct |
353 ms |
824 KB |
Output is correct |
64 |
Correct |
349 ms |
592 KB |
Output is correct |
65 |
Correct |
313 ms |
348 KB |
Output is correct |
66 |
Correct |
308 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
580 KB |
Output is correct |
12 |
Correct |
4 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
580 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
13 ms |
344 KB |
Output is correct |
22 |
Correct |
18 ms |
348 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
36 ms |
348 KB |
Output is correct |
25 |
Correct |
29 ms |
572 KB |
Output is correct |
26 |
Correct |
34 ms |
572 KB |
Output is correct |
27 |
Correct |
39 ms |
564 KB |
Output is correct |
28 |
Correct |
33 ms |
348 KB |
Output is correct |
29 |
Correct |
33 ms |
348 KB |
Output is correct |
30 |
Correct |
39 ms |
348 KB |
Output is correct |
31 |
Correct |
32 ms |
348 KB |
Output is correct |
32 |
Correct |
32 ms |
348 KB |
Output is correct |
33 |
Correct |
35 ms |
348 KB |
Output is correct |
34 |
Correct |
32 ms |
348 KB |
Output is correct |
35 |
Correct |
32 ms |
348 KB |
Output is correct |
36 |
Correct |
43 ms |
348 KB |
Output is correct |
37 |
Correct |
128 ms |
568 KB |
Output is correct |
38 |
Correct |
128 ms |
596 KB |
Output is correct |
39 |
Correct |
197 ms |
348 KB |
Output is correct |
40 |
Correct |
241 ms |
568 KB |
Output is correct |
41 |
Correct |
233 ms |
344 KB |
Output is correct |
42 |
Correct |
198 ms |
592 KB |
Output is correct |
43 |
Correct |
195 ms |
568 KB |
Output is correct |
44 |
Correct |
209 ms |
596 KB |
Output is correct |
45 |
Correct |
209 ms |
556 KB |
Output is correct |
46 |
Correct |
227 ms |
348 KB |
Output is correct |
47 |
Correct |
211 ms |
592 KB |
Output is correct |
48 |
Correct |
216 ms |
548 KB |
Output is correct |
49 |
Correct |
209 ms |
604 KB |
Output is correct |
50 |
Correct |
219 ms |
592 KB |
Output is correct |
51 |
Correct |
202 ms |
348 KB |
Output is correct |
52 |
Correct |
264 ms |
556 KB |
Output is correct |
53 |
Correct |
302 ms |
608 KB |
Output is correct |
54 |
Correct |
405 ms |
592 KB |
Output is correct |
55 |
Correct |
456 ms |
820 KB |
Output is correct |
56 |
Correct |
308 ms |
596 KB |
Output is correct |
57 |
Correct |
424 ms |
848 KB |
Output is correct |
58 |
Correct |
399 ms |
556 KB |
Output is correct |
59 |
Correct |
409 ms |
552 KB |
Output is correct |
60 |
Correct |
398 ms |
348 KB |
Output is correct |
61 |
Correct |
416 ms |
564 KB |
Output is correct |
62 |
Correct |
349 ms |
592 KB |
Output is correct |
63 |
Correct |
353 ms |
824 KB |
Output is correct |
64 |
Correct |
349 ms |
592 KB |
Output is correct |
65 |
Correct |
313 ms |
348 KB |
Output is correct |
66 |
Correct |
308 ms |
348 KB |
Output is correct |
67 |
Correct |
534 ms |
596 KB |
Output is correct |
68 |
Correct |
2 ms |
344 KB |
Output is correct |
69 |
Correct |
882 ms |
1080 KB |
Output is correct |
70 |
Correct |
847 ms |
852 KB |
Output is correct |
71 |
Correct |
837 ms |
852 KB |
Output is correct |
72 |
Correct |
826 ms |
348 KB |
Output is correct |
73 |
Correct |
837 ms |
348 KB |
Output is correct |
74 |
Correct |
902 ms |
1064 KB |
Output is correct |
75 |
Correct |
871 ms |
1068 KB |
Output is correct |
76 |
Correct |
910 ms |
1080 KB |
Output is correct |
77 |
Correct |
924 ms |
1064 KB |
Output is correct |