#include<bits/stdc++.h>
using namespace std;
const int N = 501;
int n , a[N] , dp[N*N+505] , ans[N * N];
int main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
int s =0;
for(int i = 0;i < n; ++i)cin >> a[i] ,s+=a[i];
dp[0] = 1;
for(int i = 0; i < n; ++i){
for(int j = s; j>= a[i]; --j)dp[j] += dp[j - a[i]];
}
if(s & 1 || dp[s/2]==0){
cout << 0; return 0;
}
vector<int> y;
for(int i = 0; i <n; ++i){
for(int j = a[i]; j <= s; ++j)dp[j] -= dp[j - a[i]];
for(int j = 1; j<= s; ++j){
int z = s - a[i] + j;
//cout << j << " " << S << endl;
if(z&1 || !dp[z/2])continue;
ans[j]++;
if(ans[j]==n)y.emplace_back(j);
}
for(int j = s; j >= a[i]; --j)dp[j] += dp[j-a[i]];
}
cout << y.size()<<endl;
for(int x : y)cout << x << " ";
//cout << dp[s/2];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
424 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
424 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
424 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
308 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
332 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
6 ms |
316 KB |
Output is correct |
28 |
Correct |
6 ms |
324 KB |
Output is correct |
29 |
Correct |
5 ms |
332 KB |
Output is correct |
30 |
Correct |
3 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
316 KB |
Output is correct |
33 |
Correct |
6 ms |
332 KB |
Output is correct |
34 |
Correct |
7 ms |
332 KB |
Output is correct |
35 |
Correct |
7 ms |
332 KB |
Output is correct |
36 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
424 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
308 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
332 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
6 ms |
316 KB |
Output is correct |
28 |
Correct |
6 ms |
324 KB |
Output is correct |
29 |
Correct |
5 ms |
332 KB |
Output is correct |
30 |
Correct |
3 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
316 KB |
Output is correct |
33 |
Correct |
6 ms |
332 KB |
Output is correct |
34 |
Correct |
7 ms |
332 KB |
Output is correct |
35 |
Correct |
7 ms |
332 KB |
Output is correct |
36 |
Correct |
3 ms |
332 KB |
Output is correct |
37 |
Correct |
20 ms |
604 KB |
Output is correct |
38 |
Correct |
21 ms |
580 KB |
Output is correct |
39 |
Correct |
72 ms |
788 KB |
Output is correct |
40 |
Correct |
42 ms |
696 KB |
Output is correct |
41 |
Correct |
98 ms |
872 KB |
Output is correct |
42 |
Correct |
41 ms |
660 KB |
Output is correct |
43 |
Correct |
65 ms |
1116 KB |
Output is correct |
44 |
Correct |
67 ms |
1124 KB |
Output is correct |
45 |
Correct |
70 ms |
1124 KB |
Output is correct |
46 |
Correct |
43 ms |
460 KB |
Output is correct |
47 |
Correct |
43 ms |
692 KB |
Output is correct |
48 |
Correct |
71 ms |
1044 KB |
Output is correct |
49 |
Correct |
76 ms |
836 KB |
Output is correct |
50 |
Correct |
48 ms |
696 KB |
Output is correct |
51 |
Correct |
5 ms |
332 KB |
Output is correct |
52 |
Correct |
97 ms |
1232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
424 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
308 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
332 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
6 ms |
316 KB |
Output is correct |
28 |
Correct |
6 ms |
324 KB |
Output is correct |
29 |
Correct |
5 ms |
332 KB |
Output is correct |
30 |
Correct |
3 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
316 KB |
Output is correct |
33 |
Correct |
6 ms |
332 KB |
Output is correct |
34 |
Correct |
7 ms |
332 KB |
Output is correct |
35 |
Correct |
7 ms |
332 KB |
Output is correct |
36 |
Correct |
3 ms |
332 KB |
Output is correct |
37 |
Correct |
20 ms |
604 KB |
Output is correct |
38 |
Correct |
21 ms |
580 KB |
Output is correct |
39 |
Correct |
72 ms |
788 KB |
Output is correct |
40 |
Correct |
42 ms |
696 KB |
Output is correct |
41 |
Correct |
98 ms |
872 KB |
Output is correct |
42 |
Correct |
41 ms |
660 KB |
Output is correct |
43 |
Correct |
65 ms |
1116 KB |
Output is correct |
44 |
Correct |
67 ms |
1124 KB |
Output is correct |
45 |
Correct |
70 ms |
1124 KB |
Output is correct |
46 |
Correct |
43 ms |
460 KB |
Output is correct |
47 |
Correct |
43 ms |
692 KB |
Output is correct |
48 |
Correct |
71 ms |
1044 KB |
Output is correct |
49 |
Correct |
76 ms |
836 KB |
Output is correct |
50 |
Correct |
48 ms |
696 KB |
Output is correct |
51 |
Correct |
5 ms |
332 KB |
Output is correct |
52 |
Correct |
97 ms |
1232 KB |
Output is correct |
53 |
Correct |
64 ms |
920 KB |
Output is correct |
54 |
Correct |
95 ms |
1116 KB |
Output is correct |
55 |
Correct |
186 ms |
1776 KB |
Output is correct |
56 |
Correct |
81 ms |
1092 KB |
Output is correct |
57 |
Correct |
189 ms |
1788 KB |
Output is correct |
58 |
Correct |
99 ms |
1220 KB |
Output is correct |
59 |
Correct |
139 ms |
1284 KB |
Output is correct |
60 |
Correct |
11 ms |
560 KB |
Output is correct |
61 |
Correct |
134 ms |
1488 KB |
Output is correct |
62 |
Correct |
143 ms |
1568 KB |
Output is correct |
63 |
Correct |
165 ms |
1632 KB |
Output is correct |
64 |
Correct |
160 ms |
1616 KB |
Output is correct |
65 |
Correct |
67 ms |
676 KB |
Output is correct |
66 |
Correct |
69 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
424 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
308 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
332 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
6 ms |
316 KB |
Output is correct |
28 |
Correct |
6 ms |
324 KB |
Output is correct |
29 |
Correct |
5 ms |
332 KB |
Output is correct |
30 |
Correct |
3 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
316 KB |
Output is correct |
33 |
Correct |
6 ms |
332 KB |
Output is correct |
34 |
Correct |
7 ms |
332 KB |
Output is correct |
35 |
Correct |
7 ms |
332 KB |
Output is correct |
36 |
Correct |
3 ms |
332 KB |
Output is correct |
37 |
Correct |
20 ms |
604 KB |
Output is correct |
38 |
Correct |
21 ms |
580 KB |
Output is correct |
39 |
Correct |
72 ms |
788 KB |
Output is correct |
40 |
Correct |
42 ms |
696 KB |
Output is correct |
41 |
Correct |
98 ms |
872 KB |
Output is correct |
42 |
Correct |
41 ms |
660 KB |
Output is correct |
43 |
Correct |
65 ms |
1116 KB |
Output is correct |
44 |
Correct |
67 ms |
1124 KB |
Output is correct |
45 |
Correct |
70 ms |
1124 KB |
Output is correct |
46 |
Correct |
43 ms |
460 KB |
Output is correct |
47 |
Correct |
43 ms |
692 KB |
Output is correct |
48 |
Correct |
71 ms |
1044 KB |
Output is correct |
49 |
Correct |
76 ms |
836 KB |
Output is correct |
50 |
Correct |
48 ms |
696 KB |
Output is correct |
51 |
Correct |
5 ms |
332 KB |
Output is correct |
52 |
Correct |
97 ms |
1232 KB |
Output is correct |
53 |
Correct |
64 ms |
920 KB |
Output is correct |
54 |
Correct |
95 ms |
1116 KB |
Output is correct |
55 |
Correct |
186 ms |
1776 KB |
Output is correct |
56 |
Correct |
81 ms |
1092 KB |
Output is correct |
57 |
Correct |
189 ms |
1788 KB |
Output is correct |
58 |
Correct |
99 ms |
1220 KB |
Output is correct |
59 |
Correct |
139 ms |
1284 KB |
Output is correct |
60 |
Correct |
11 ms |
560 KB |
Output is correct |
61 |
Correct |
134 ms |
1488 KB |
Output is correct |
62 |
Correct |
143 ms |
1568 KB |
Output is correct |
63 |
Correct |
165 ms |
1632 KB |
Output is correct |
64 |
Correct |
160 ms |
1616 KB |
Output is correct |
65 |
Correct |
67 ms |
676 KB |
Output is correct |
66 |
Correct |
69 ms |
692 KB |
Output is correct |
67 |
Correct |
150 ms |
1452 KB |
Output is correct |
68 |
Correct |
31 ms |
788 KB |
Output is correct |
69 |
Correct |
505 ms |
3176 KB |
Output is correct |
70 |
Correct |
303 ms |
2076 KB |
Output is correct |
71 |
Correct |
277 ms |
1964 KB |
Output is correct |
72 |
Correct |
287 ms |
1308 KB |
Output is correct |
73 |
Correct |
309 ms |
1280 KB |
Output is correct |
74 |
Correct |
535 ms |
3208 KB |
Output is correct |
75 |
Correct |
410 ms |
2684 KB |
Output is correct |
76 |
Correct |
577 ms |
3368 KB |
Output is correct |
77 |
Correct |
563 ms |
3440 KB |
Output is correct |