#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (auto& i : a) cin >> i;
int sm = accumulate(all(a), 0);
vector<uint64_t> dp(sm + 1, 0);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = sm - a[i]; j >= 0; --j) {
dp[j + a[i]] += dp[j];
}
}
if (sm & 1 || dp[sm / 2] == 0) {
cout << "0\n";
return 0;
}
vector<int> ans(sm + 1, 0);
for (int i = 1; i <= sm; ++i) ans[i] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= sm - a[i]; ++j) {
dp[j + a[i]] -= dp[j];
}
for (int k = 1; k <= sm; ++k) {
if ((sm - a[i] + k) & 1) ans[k] = 0;
int tar = (sm - a[i] + k) / 2;
if ((tar <= sm && dp[tar]) || (0 <= tar - k && tar - k <= sm && dp[tar - k])) {}
else ans[k] = 0;
}
for (int j = sm - a[i]; j >= 0; --j) {
dp[j + a[i]] += dp[j];
}
}
cout << accumulate(all(ans), 0) << '\n';
for (int i = 1; i <= sm; ++i) {
if (ans[i]) cout << i << ' ';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
4 ms |
344 KB |
Output is correct |
36 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
4 ms |
344 KB |
Output is correct |
36 |
Correct |
2 ms |
344 KB |
Output is correct |
37 |
Correct |
10 ms |
600 KB |
Output is correct |
38 |
Correct |
11 ms |
600 KB |
Output is correct |
39 |
Correct |
48 ms |
1112 KB |
Output is correct |
40 |
Correct |
25 ms |
856 KB |
Output is correct |
41 |
Correct |
68 ms |
1112 KB |
Output is correct |
42 |
Correct |
19 ms |
848 KB |
Output is correct |
43 |
Correct |
37 ms |
1104 KB |
Output is correct |
44 |
Correct |
36 ms |
1116 KB |
Output is correct |
45 |
Correct |
36 ms |
1112 KB |
Output is correct |
46 |
Correct |
25 ms |
600 KB |
Output is correct |
47 |
Correct |
25 ms |
856 KB |
Output is correct |
48 |
Correct |
44 ms |
1112 KB |
Output is correct |
49 |
Correct |
45 ms |
1168 KB |
Output is correct |
50 |
Correct |
22 ms |
860 KB |
Output is correct |
51 |
Correct |
4 ms |
600 KB |
Output is correct |
52 |
Correct |
53 ms |
1360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
4 ms |
344 KB |
Output is correct |
36 |
Correct |
2 ms |
344 KB |
Output is correct |
37 |
Correct |
10 ms |
600 KB |
Output is correct |
38 |
Correct |
11 ms |
600 KB |
Output is correct |
39 |
Correct |
48 ms |
1112 KB |
Output is correct |
40 |
Correct |
25 ms |
856 KB |
Output is correct |
41 |
Correct |
68 ms |
1112 KB |
Output is correct |
42 |
Correct |
19 ms |
848 KB |
Output is correct |
43 |
Correct |
37 ms |
1104 KB |
Output is correct |
44 |
Correct |
36 ms |
1116 KB |
Output is correct |
45 |
Correct |
36 ms |
1112 KB |
Output is correct |
46 |
Correct |
25 ms |
600 KB |
Output is correct |
47 |
Correct |
25 ms |
856 KB |
Output is correct |
48 |
Correct |
44 ms |
1112 KB |
Output is correct |
49 |
Correct |
45 ms |
1168 KB |
Output is correct |
50 |
Correct |
22 ms |
860 KB |
Output is correct |
51 |
Correct |
4 ms |
600 KB |
Output is correct |
52 |
Correct |
53 ms |
1360 KB |
Output is correct |
53 |
Correct |
37 ms |
1104 KB |
Output is correct |
54 |
Correct |
50 ms |
1112 KB |
Output is correct |
55 |
Correct |
113 ms |
1872 KB |
Output is correct |
56 |
Correct |
43 ms |
1112 KB |
Output is correct |
57 |
Correct |
115 ms |
2076 KB |
Output is correct |
58 |
Correct |
54 ms |
1160 KB |
Output is correct |
59 |
Correct |
76 ms |
1360 KB |
Output is correct |
60 |
Correct |
10 ms |
856 KB |
Output is correct |
61 |
Correct |
76 ms |
1452 KB |
Output is correct |
62 |
Correct |
85 ms |
1840 KB |
Output is correct |
63 |
Correct |
88 ms |
1916 KB |
Output is correct |
64 |
Correct |
94 ms |
1872 KB |
Output is correct |
65 |
Correct |
48 ms |
1000 KB |
Output is correct |
66 |
Correct |
56 ms |
1064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
4 ms |
344 KB |
Output is correct |
36 |
Correct |
2 ms |
344 KB |
Output is correct |
37 |
Correct |
10 ms |
600 KB |
Output is correct |
38 |
Correct |
11 ms |
600 KB |
Output is correct |
39 |
Correct |
48 ms |
1112 KB |
Output is correct |
40 |
Correct |
25 ms |
856 KB |
Output is correct |
41 |
Correct |
68 ms |
1112 KB |
Output is correct |
42 |
Correct |
19 ms |
848 KB |
Output is correct |
43 |
Correct |
37 ms |
1104 KB |
Output is correct |
44 |
Correct |
36 ms |
1116 KB |
Output is correct |
45 |
Correct |
36 ms |
1112 KB |
Output is correct |
46 |
Correct |
25 ms |
600 KB |
Output is correct |
47 |
Correct |
25 ms |
856 KB |
Output is correct |
48 |
Correct |
44 ms |
1112 KB |
Output is correct |
49 |
Correct |
45 ms |
1168 KB |
Output is correct |
50 |
Correct |
22 ms |
860 KB |
Output is correct |
51 |
Correct |
4 ms |
600 KB |
Output is correct |
52 |
Correct |
53 ms |
1360 KB |
Output is correct |
53 |
Correct |
37 ms |
1104 KB |
Output is correct |
54 |
Correct |
50 ms |
1112 KB |
Output is correct |
55 |
Correct |
113 ms |
1872 KB |
Output is correct |
56 |
Correct |
43 ms |
1112 KB |
Output is correct |
57 |
Correct |
115 ms |
2076 KB |
Output is correct |
58 |
Correct |
54 ms |
1160 KB |
Output is correct |
59 |
Correct |
76 ms |
1360 KB |
Output is correct |
60 |
Correct |
10 ms |
856 KB |
Output is correct |
61 |
Correct |
76 ms |
1452 KB |
Output is correct |
62 |
Correct |
85 ms |
1840 KB |
Output is correct |
63 |
Correct |
88 ms |
1916 KB |
Output is correct |
64 |
Correct |
94 ms |
1872 KB |
Output is correct |
65 |
Correct |
48 ms |
1000 KB |
Output is correct |
66 |
Correct |
56 ms |
1064 KB |
Output is correct |
67 |
Correct |
91 ms |
1616 KB |
Output is correct |
68 |
Correct |
27 ms |
1368 KB |
Output is correct |
69 |
Correct |
282 ms |
3412 KB |
Output is correct |
70 |
Correct |
158 ms |
2208 KB |
Output is correct |
71 |
Correct |
155 ms |
2168 KB |
Output is correct |
72 |
Correct |
154 ms |
1696 KB |
Output is correct |
73 |
Correct |
161 ms |
1948 KB |
Output is correct |
74 |
Correct |
287 ms |
3596 KB |
Output is correct |
75 |
Correct |
222 ms |
3024 KB |
Output is correct |
76 |
Correct |
334 ms |
3924 KB |
Output is correct |
77 |
Correct |
318 ms |
3924 KB |
Output is correct |