#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
vector<int> a(N);
for (int &value : a) {
cin >> value;
}
int S = accumulate(a.begin(), a.end(), 0);
for (int i = 0; i < N; i++) {
if (a[i] % 2 != a[0] % 2 || S % 2) {
cout << "0\n";
exit(0);
}
}
vector<uint64_t> rnd(N);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < N; i++) {
rnd[i] = rng();
}
vector<uint64_t> dp(S + 1);
dp[0] = 1;
for (int i = 0; i < N; i++) {
for (int j = S - a[i]; j >= 0; j--) {
dp[j + a[i]] += dp[j];
}
}
if (dp[S / 2] == 0) {
cout << "0\n";
exit(0);
}
vector<bool> good(S + 1, true);
for (int i = 0; i < N; i++) {
for (int j = 0; j + a[i] <= S; j++) {
dp[j + a[i]] -= dp[j];
}
vector<bool> new_good(S + 1);
for (int j = 0; j <= S; j++) {
if (dp[j] > 0) {
new_good[abs(2 * j - (S - a[i]))] = true;
}
}
for (int j = 0; j <= S; j++) {
good[j] = good[j] && new_good[j];
}
for (int j = S - a[i]; j >= 0; j--) {
dp[j + a[i]] += dp[j];
}
}
vector<int> answer;
for (int i = 1; i <= S; i++) {
if (good[i]) {
answer.push_back(i);
}
}
int k = (int)answer.size();
cout << k << "\n";
for (int i = 0; i < k; i++) {
cout << answer[i] << " \n"[i + 1 == k];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
4 ms |
344 KB |
Output is correct |
26 |
Correct |
5 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
524 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
488 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
4 ms |
348 KB |
Output is correct |
35 |
Correct |
4 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
4 ms |
344 KB |
Output is correct |
26 |
Correct |
5 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
524 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
488 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
4 ms |
348 KB |
Output is correct |
35 |
Correct |
4 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
492 KB |
Output is correct |
37 |
Correct |
20 ms |
600 KB |
Output is correct |
38 |
Correct |
20 ms |
624 KB |
Output is correct |
39 |
Correct |
54 ms |
856 KB |
Output is correct |
40 |
Correct |
44 ms |
732 KB |
Output is correct |
41 |
Correct |
69 ms |
860 KB |
Output is correct |
42 |
Correct |
37 ms |
848 KB |
Output is correct |
43 |
Correct |
72 ms |
1144 KB |
Output is correct |
44 |
Correct |
73 ms |
1108 KB |
Output is correct |
45 |
Correct |
70 ms |
1152 KB |
Output is correct |
46 |
Correct |
32 ms |
604 KB |
Output is correct |
47 |
Correct |
41 ms |
716 KB |
Output is correct |
48 |
Correct |
69 ms |
1108 KB |
Output is correct |
49 |
Correct |
61 ms |
948 KB |
Output is correct |
50 |
Correct |
41 ms |
724 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
91 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
4 ms |
344 KB |
Output is correct |
26 |
Correct |
5 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
524 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
488 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
4 ms |
348 KB |
Output is correct |
35 |
Correct |
4 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
492 KB |
Output is correct |
37 |
Correct |
20 ms |
600 KB |
Output is correct |
38 |
Correct |
20 ms |
624 KB |
Output is correct |
39 |
Correct |
54 ms |
856 KB |
Output is correct |
40 |
Correct |
44 ms |
732 KB |
Output is correct |
41 |
Correct |
69 ms |
860 KB |
Output is correct |
42 |
Correct |
37 ms |
848 KB |
Output is correct |
43 |
Correct |
72 ms |
1144 KB |
Output is correct |
44 |
Correct |
73 ms |
1108 KB |
Output is correct |
45 |
Correct |
70 ms |
1152 KB |
Output is correct |
46 |
Correct |
32 ms |
604 KB |
Output is correct |
47 |
Correct |
41 ms |
716 KB |
Output is correct |
48 |
Correct |
69 ms |
1108 KB |
Output is correct |
49 |
Correct |
61 ms |
948 KB |
Output is correct |
50 |
Correct |
41 ms |
724 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
91 ms |
1368 KB |
Output is correct |
53 |
Correct |
69 ms |
1104 KB |
Output is correct |
54 |
Correct |
94 ms |
1108 KB |
Output is correct |
55 |
Correct |
181 ms |
1752 KB |
Output is correct |
56 |
Correct |
84 ms |
1148 KB |
Output is correct |
57 |
Correct |
193 ms |
2004 KB |
Output is correct |
58 |
Correct |
105 ms |
1212 KB |
Output is correct |
59 |
Correct |
127 ms |
1496 KB |
Output is correct |
60 |
Correct |
1 ms |
344 KB |
Output is correct |
61 |
Correct |
134 ms |
1524 KB |
Output is correct |
62 |
Correct |
140 ms |
1580 KB |
Output is correct |
63 |
Correct |
149 ms |
1752 KB |
Output is correct |
64 |
Correct |
153 ms |
1664 KB |
Output is correct |
65 |
Correct |
54 ms |
856 KB |
Output is correct |
66 |
Correct |
60 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
4 ms |
344 KB |
Output is correct |
26 |
Correct |
5 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
524 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
488 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
4 ms |
348 KB |
Output is correct |
35 |
Correct |
4 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
492 KB |
Output is correct |
37 |
Correct |
20 ms |
600 KB |
Output is correct |
38 |
Correct |
20 ms |
624 KB |
Output is correct |
39 |
Correct |
54 ms |
856 KB |
Output is correct |
40 |
Correct |
44 ms |
732 KB |
Output is correct |
41 |
Correct |
69 ms |
860 KB |
Output is correct |
42 |
Correct |
37 ms |
848 KB |
Output is correct |
43 |
Correct |
72 ms |
1144 KB |
Output is correct |
44 |
Correct |
73 ms |
1108 KB |
Output is correct |
45 |
Correct |
70 ms |
1152 KB |
Output is correct |
46 |
Correct |
32 ms |
604 KB |
Output is correct |
47 |
Correct |
41 ms |
716 KB |
Output is correct |
48 |
Correct |
69 ms |
1108 KB |
Output is correct |
49 |
Correct |
61 ms |
948 KB |
Output is correct |
50 |
Correct |
41 ms |
724 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
91 ms |
1368 KB |
Output is correct |
53 |
Correct |
69 ms |
1104 KB |
Output is correct |
54 |
Correct |
94 ms |
1108 KB |
Output is correct |
55 |
Correct |
181 ms |
1752 KB |
Output is correct |
56 |
Correct |
84 ms |
1148 KB |
Output is correct |
57 |
Correct |
193 ms |
2004 KB |
Output is correct |
58 |
Correct |
105 ms |
1212 KB |
Output is correct |
59 |
Correct |
127 ms |
1496 KB |
Output is correct |
60 |
Correct |
1 ms |
344 KB |
Output is correct |
61 |
Correct |
134 ms |
1524 KB |
Output is correct |
62 |
Correct |
140 ms |
1580 KB |
Output is correct |
63 |
Correct |
149 ms |
1752 KB |
Output is correct |
64 |
Correct |
153 ms |
1664 KB |
Output is correct |
65 |
Correct |
54 ms |
856 KB |
Output is correct |
66 |
Correct |
60 ms |
856 KB |
Output is correct |
67 |
Correct |
151 ms |
1484 KB |
Output is correct |
68 |
Correct |
41 ms |
1368 KB |
Output is correct |
69 |
Correct |
485 ms |
3268 KB |
Output is correct |
70 |
Correct |
312 ms |
2132 KB |
Output is correct |
71 |
Correct |
294 ms |
2008 KB |
Output is correct |
72 |
Correct |
0 ms |
344 KB |
Output is correct |
73 |
Correct |
0 ms |
348 KB |
Output is correct |
74 |
Correct |
546 ms |
3376 KB |
Output is correct |
75 |
Correct |
446 ms |
2768 KB |
Output is correct |
76 |
Correct |
558 ms |
3528 KB |
Output is correct |
77 |
Correct |
538 ms |
3456 KB |
Output is correct |