#include <bitset>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >> n;
if(n % 2 != 0){
cout << 0;
return 0;
}
vector<int> a(n);
for(int i = 0; i < n; i ++) cin >> a[i];
int k = a[0] & -a[0], s = 0;
for(int i = 0; i < n; i ++){
if((a[i] & -a[i]) != k){
cout << 0;
return 0;
}
a[i] /= k;
s += a[i];
}
vector<bitset<500>> dp(s+1);
vector<bool> can(s+1);
can[0] = true;
int s1 = 0;
for(int i = 0; i < n; i ++){
s1 += a[i];
for(int j = s1; j >= a[i]; j --){
if(can[j - a[i]]){
if(!can[j]){
dp[j] = dp[j-a[i]];
dp[j].set(i, 1);
}
else dp[j] = dp[j] & dp[j-a[i]];
can[j] = true;
}
}
}
if(!can[s/2]){
cout << 0;
return 0;
}
vector<int> res;
for(int x = 1; x <= s; x += 2){
bool f = true;
for(int i = 0; i < n; i ++)
if(!can[(s + x - a[i]) / 2] || dp[(s + x - a[i]) / 2][i]){
f = false;
break;
}
if(f)
res.push_back(x);
}
cout << res.size() << '\n';
for(int x:res) cout << x * k << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
1012 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
688 KB |
Output is correct |
29 |
Correct |
3 ms |
860 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
6 ms |
860 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
3 ms |
948 KB |
Output is correct |
36 |
Correct |
4 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
1012 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
688 KB |
Output is correct |
29 |
Correct |
3 ms |
860 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
6 ms |
860 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
3 ms |
948 KB |
Output is correct |
36 |
Correct |
4 ms |
600 KB |
Output is correct |
37 |
Correct |
27 ms |
1660 KB |
Output is correct |
38 |
Correct |
28 ms |
1880 KB |
Output is correct |
39 |
Correct |
9 ms |
4188 KB |
Output is correct |
40 |
Correct |
60 ms |
2456 KB |
Output is correct |
41 |
Correct |
6 ms |
2652 KB |
Output is correct |
42 |
Correct |
52 ms |
2384 KB |
Output is correct |
43 |
Correct |
97 ms |
4184 KB |
Output is correct |
44 |
Correct |
91 ms |
4204 KB |
Output is correct |
45 |
Correct |
93 ms |
4236 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
55 ms |
2484 KB |
Output is correct |
48 |
Correct |
62 ms |
4436 KB |
Output is correct |
49 |
Correct |
37 ms |
4184 KB |
Output is correct |
50 |
Correct |
57 ms |
2480 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
105 ms |
5096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
1012 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
688 KB |
Output is correct |
29 |
Correct |
3 ms |
860 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
6 ms |
860 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
3 ms |
948 KB |
Output is correct |
36 |
Correct |
4 ms |
600 KB |
Output is correct |
37 |
Correct |
27 ms |
1660 KB |
Output is correct |
38 |
Correct |
28 ms |
1880 KB |
Output is correct |
39 |
Correct |
9 ms |
4188 KB |
Output is correct |
40 |
Correct |
60 ms |
2456 KB |
Output is correct |
41 |
Correct |
6 ms |
2652 KB |
Output is correct |
42 |
Correct |
52 ms |
2384 KB |
Output is correct |
43 |
Correct |
97 ms |
4184 KB |
Output is correct |
44 |
Correct |
91 ms |
4204 KB |
Output is correct |
45 |
Correct |
93 ms |
4236 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
55 ms |
2484 KB |
Output is correct |
48 |
Correct |
62 ms |
4436 KB |
Output is correct |
49 |
Correct |
37 ms |
4184 KB |
Output is correct |
50 |
Correct |
57 ms |
2480 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
105 ms |
5096 KB |
Output is correct |
53 |
Correct |
94 ms |
3412 KB |
Output is correct |
54 |
Correct |
132 ms |
4164 KB |
Output is correct |
55 |
Correct |
231 ms |
7768 KB |
Output is correct |
56 |
Correct |
119 ms |
4180 KB |
Output is correct |
57 |
Correct |
251 ms |
8164 KB |
Output is correct |
58 |
Correct |
148 ms |
4572 KB |
Output is correct |
59 |
Correct |
181 ms |
5620 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
222 ms |
6196 KB |
Output is correct |
62 |
Correct |
224 ms |
6828 KB |
Output is correct |
63 |
Correct |
213 ms |
7312 KB |
Output is correct |
64 |
Correct |
203 ms |
7376 KB |
Output is correct |
65 |
Correct |
7 ms |
1112 KB |
Output is correct |
66 |
Correct |
32 ms |
3672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
1012 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
688 KB |
Output is correct |
29 |
Correct |
3 ms |
860 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
6 ms |
860 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
3 ms |
948 KB |
Output is correct |
36 |
Correct |
4 ms |
600 KB |
Output is correct |
37 |
Correct |
27 ms |
1660 KB |
Output is correct |
38 |
Correct |
28 ms |
1880 KB |
Output is correct |
39 |
Correct |
9 ms |
4188 KB |
Output is correct |
40 |
Correct |
60 ms |
2456 KB |
Output is correct |
41 |
Correct |
6 ms |
2652 KB |
Output is correct |
42 |
Correct |
52 ms |
2384 KB |
Output is correct |
43 |
Correct |
97 ms |
4184 KB |
Output is correct |
44 |
Correct |
91 ms |
4204 KB |
Output is correct |
45 |
Correct |
93 ms |
4236 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
55 ms |
2484 KB |
Output is correct |
48 |
Correct |
62 ms |
4436 KB |
Output is correct |
49 |
Correct |
37 ms |
4184 KB |
Output is correct |
50 |
Correct |
57 ms |
2480 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
105 ms |
5096 KB |
Output is correct |
53 |
Correct |
94 ms |
3412 KB |
Output is correct |
54 |
Correct |
132 ms |
4164 KB |
Output is correct |
55 |
Correct |
231 ms |
7768 KB |
Output is correct |
56 |
Correct |
119 ms |
4180 KB |
Output is correct |
57 |
Correct |
251 ms |
8164 KB |
Output is correct |
58 |
Correct |
148 ms |
4572 KB |
Output is correct |
59 |
Correct |
181 ms |
5620 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
222 ms |
6196 KB |
Output is correct |
62 |
Correct |
224 ms |
6828 KB |
Output is correct |
63 |
Correct |
213 ms |
7312 KB |
Output is correct |
64 |
Correct |
203 ms |
7376 KB |
Output is correct |
65 |
Correct |
7 ms |
1112 KB |
Output is correct |
66 |
Correct |
32 ms |
3672 KB |
Output is correct |
67 |
Correct |
165 ms |
5832 KB |
Output is correct |
68 |
Correct |
0 ms |
348 KB |
Output is correct |
69 |
Correct |
677 ms |
14860 KB |
Output is correct |
70 |
Correct |
446 ms |
9168 KB |
Output is correct |
71 |
Correct |
432 ms |
8908 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
0 ms |
348 KB |
Output is correct |
74 |
Correct |
736 ms |
15624 KB |
Output is correct |
75 |
Correct |
586 ms |
12244 KB |
Output is correct |
76 |
Correct |
680 ms |
16912 KB |
Output is correct |
77 |
Correct |
751 ms |
16464 KB |
Output is correct |