#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 505, M = 125005;
int n;
int a[N], f[M], cnt[2 * M];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
f[0] = 1;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
for (int j = M - 1; j >= a[i]; --j) {
f[j] += f[j - a[i]];
}
}
int sum = accumulate(a + 1, a + n + 1, 0);
if (!f[sum / 2]) {
cout << 0 << "\n";
exit(0);
}
for (int i = 1; i <= n; ++i) {
sum -= a[i];
for (int j = a[i]; j < M; ++j) {
f[j] -= f[j - a[i]];
}
for (int j = 0; j <= sum / 2; ++j) {
if (f[j]) {
++cnt[sum - 2 * j];
}
}
for (int j = M - 1; j >= a[i]; --j) {
f[j] += f[j - a[i]];
}
sum += a[i];
}
int res = 0;
for (int i = 1; i < 2 * M; ++i) {
res += cnt[i] == n;
}
cout << res << "\n";
for (int i = 1; i < 2 * M; ++i) {
if (cnt[i] == n) {
cout << i << " ";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
952 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
856 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
952 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
856 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
6 ms |
856 KB |
Output is correct |
11 |
Correct |
6 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
860 KB |
Output is correct |
16 |
Correct |
6 ms |
960 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
952 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
10 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
952 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
856 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
6 ms |
856 KB |
Output is correct |
11 |
Correct |
6 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
860 KB |
Output is correct |
16 |
Correct |
6 ms |
960 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
952 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
10 ms |
860 KB |
Output is correct |
21 |
Correct |
11 ms |
860 KB |
Output is correct |
22 |
Correct |
12 ms |
956 KB |
Output is correct |
23 |
Correct |
9 ms |
856 KB |
Output is correct |
24 |
Correct |
15 ms |
860 KB |
Output is correct |
25 |
Correct |
16 ms |
860 KB |
Output is correct |
26 |
Correct |
17 ms |
860 KB |
Output is correct |
27 |
Correct |
17 ms |
956 KB |
Output is correct |
28 |
Correct |
16 ms |
988 KB |
Output is correct |
29 |
Correct |
16 ms |
860 KB |
Output is correct |
30 |
Correct |
16 ms |
860 KB |
Output is correct |
31 |
Correct |
16 ms |
956 KB |
Output is correct |
32 |
Correct |
17 ms |
860 KB |
Output is correct |
33 |
Correct |
16 ms |
860 KB |
Output is correct |
34 |
Correct |
17 ms |
860 KB |
Output is correct |
35 |
Correct |
23 ms |
856 KB |
Output is correct |
36 |
Correct |
17 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
952 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
856 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
6 ms |
856 KB |
Output is correct |
11 |
Correct |
6 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
860 KB |
Output is correct |
16 |
Correct |
6 ms |
960 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
952 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
10 ms |
860 KB |
Output is correct |
21 |
Correct |
11 ms |
860 KB |
Output is correct |
22 |
Correct |
12 ms |
956 KB |
Output is correct |
23 |
Correct |
9 ms |
856 KB |
Output is correct |
24 |
Correct |
15 ms |
860 KB |
Output is correct |
25 |
Correct |
16 ms |
860 KB |
Output is correct |
26 |
Correct |
17 ms |
860 KB |
Output is correct |
27 |
Correct |
17 ms |
956 KB |
Output is correct |
28 |
Correct |
16 ms |
988 KB |
Output is correct |
29 |
Correct |
16 ms |
860 KB |
Output is correct |
30 |
Correct |
16 ms |
860 KB |
Output is correct |
31 |
Correct |
16 ms |
956 KB |
Output is correct |
32 |
Correct |
17 ms |
860 KB |
Output is correct |
33 |
Correct |
16 ms |
860 KB |
Output is correct |
34 |
Correct |
17 ms |
860 KB |
Output is correct |
35 |
Correct |
23 ms |
856 KB |
Output is correct |
36 |
Correct |
17 ms |
860 KB |
Output is correct |
37 |
Correct |
32 ms |
860 KB |
Output is correct |
38 |
Correct |
34 ms |
1012 KB |
Output is correct |
39 |
Correct |
41 ms |
1116 KB |
Output is correct |
40 |
Correct |
44 ms |
1108 KB |
Output is correct |
41 |
Correct |
48 ms |
1116 KB |
Output is correct |
42 |
Correct |
42 ms |
1108 KB |
Output is correct |
43 |
Correct |
47 ms |
1112 KB |
Output is correct |
44 |
Correct |
43 ms |
1116 KB |
Output is correct |
45 |
Correct |
43 ms |
1164 KB |
Output is correct |
46 |
Correct |
45 ms |
856 KB |
Output is correct |
47 |
Correct |
42 ms |
1108 KB |
Output is correct |
48 |
Correct |
44 ms |
1116 KB |
Output is correct |
49 |
Correct |
44 ms |
1112 KB |
Output is correct |
50 |
Correct |
41 ms |
1104 KB |
Output is correct |
51 |
Correct |
41 ms |
856 KB |
Output is correct |
52 |
Correct |
47 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
952 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
856 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
6 ms |
856 KB |
Output is correct |
11 |
Correct |
6 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
860 KB |
Output is correct |
16 |
Correct |
6 ms |
960 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
952 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
10 ms |
860 KB |
Output is correct |
21 |
Correct |
11 ms |
860 KB |
Output is correct |
22 |
Correct |
12 ms |
956 KB |
Output is correct |
23 |
Correct |
9 ms |
856 KB |
Output is correct |
24 |
Correct |
15 ms |
860 KB |
Output is correct |
25 |
Correct |
16 ms |
860 KB |
Output is correct |
26 |
Correct |
17 ms |
860 KB |
Output is correct |
27 |
Correct |
17 ms |
956 KB |
Output is correct |
28 |
Correct |
16 ms |
988 KB |
Output is correct |
29 |
Correct |
16 ms |
860 KB |
Output is correct |
30 |
Correct |
16 ms |
860 KB |
Output is correct |
31 |
Correct |
16 ms |
956 KB |
Output is correct |
32 |
Correct |
17 ms |
860 KB |
Output is correct |
33 |
Correct |
16 ms |
860 KB |
Output is correct |
34 |
Correct |
17 ms |
860 KB |
Output is correct |
35 |
Correct |
23 ms |
856 KB |
Output is correct |
36 |
Correct |
17 ms |
860 KB |
Output is correct |
37 |
Correct |
32 ms |
860 KB |
Output is correct |
38 |
Correct |
34 ms |
1012 KB |
Output is correct |
39 |
Correct |
41 ms |
1116 KB |
Output is correct |
40 |
Correct |
44 ms |
1108 KB |
Output is correct |
41 |
Correct |
48 ms |
1116 KB |
Output is correct |
42 |
Correct |
42 ms |
1108 KB |
Output is correct |
43 |
Correct |
47 ms |
1112 KB |
Output is correct |
44 |
Correct |
43 ms |
1116 KB |
Output is correct |
45 |
Correct |
43 ms |
1164 KB |
Output is correct |
46 |
Correct |
45 ms |
856 KB |
Output is correct |
47 |
Correct |
42 ms |
1108 KB |
Output is correct |
48 |
Correct |
44 ms |
1116 KB |
Output is correct |
49 |
Correct |
44 ms |
1112 KB |
Output is correct |
50 |
Correct |
41 ms |
1104 KB |
Output is correct |
51 |
Correct |
41 ms |
856 KB |
Output is correct |
52 |
Correct |
47 ms |
1364 KB |
Output is correct |
53 |
Correct |
50 ms |
1112 KB |
Output is correct |
54 |
Correct |
61 ms |
1168 KB |
Output is correct |
55 |
Correct |
67 ms |
1620 KB |
Output is correct |
56 |
Correct |
52 ms |
1116 KB |
Output is correct |
57 |
Correct |
67 ms |
1620 KB |
Output is correct |
58 |
Correct |
62 ms |
1108 KB |
Output is correct |
59 |
Correct |
62 ms |
1360 KB |
Output is correct |
60 |
Correct |
63 ms |
1116 KB |
Output is correct |
61 |
Correct |
63 ms |
1364 KB |
Output is correct |
62 |
Correct |
60 ms |
1364 KB |
Output is correct |
63 |
Correct |
60 ms |
1616 KB |
Output is correct |
64 |
Correct |
59 ms |
1600 KB |
Output is correct |
65 |
Correct |
53 ms |
1116 KB |
Output is correct |
66 |
Correct |
53 ms |
948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
952 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
856 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
6 ms |
856 KB |
Output is correct |
11 |
Correct |
6 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
860 KB |
Output is correct |
16 |
Correct |
6 ms |
960 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
952 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
10 ms |
860 KB |
Output is correct |
21 |
Correct |
11 ms |
860 KB |
Output is correct |
22 |
Correct |
12 ms |
956 KB |
Output is correct |
23 |
Correct |
9 ms |
856 KB |
Output is correct |
24 |
Correct |
15 ms |
860 KB |
Output is correct |
25 |
Correct |
16 ms |
860 KB |
Output is correct |
26 |
Correct |
17 ms |
860 KB |
Output is correct |
27 |
Correct |
17 ms |
956 KB |
Output is correct |
28 |
Correct |
16 ms |
988 KB |
Output is correct |
29 |
Correct |
16 ms |
860 KB |
Output is correct |
30 |
Correct |
16 ms |
860 KB |
Output is correct |
31 |
Correct |
16 ms |
956 KB |
Output is correct |
32 |
Correct |
17 ms |
860 KB |
Output is correct |
33 |
Correct |
16 ms |
860 KB |
Output is correct |
34 |
Correct |
17 ms |
860 KB |
Output is correct |
35 |
Correct |
23 ms |
856 KB |
Output is correct |
36 |
Correct |
17 ms |
860 KB |
Output is correct |
37 |
Correct |
32 ms |
860 KB |
Output is correct |
38 |
Correct |
34 ms |
1012 KB |
Output is correct |
39 |
Correct |
41 ms |
1116 KB |
Output is correct |
40 |
Correct |
44 ms |
1108 KB |
Output is correct |
41 |
Correct |
48 ms |
1116 KB |
Output is correct |
42 |
Correct |
42 ms |
1108 KB |
Output is correct |
43 |
Correct |
47 ms |
1112 KB |
Output is correct |
44 |
Correct |
43 ms |
1116 KB |
Output is correct |
45 |
Correct |
43 ms |
1164 KB |
Output is correct |
46 |
Correct |
45 ms |
856 KB |
Output is correct |
47 |
Correct |
42 ms |
1108 KB |
Output is correct |
48 |
Correct |
44 ms |
1116 KB |
Output is correct |
49 |
Correct |
44 ms |
1112 KB |
Output is correct |
50 |
Correct |
41 ms |
1104 KB |
Output is correct |
51 |
Correct |
41 ms |
856 KB |
Output is correct |
52 |
Correct |
47 ms |
1364 KB |
Output is correct |
53 |
Correct |
50 ms |
1112 KB |
Output is correct |
54 |
Correct |
61 ms |
1168 KB |
Output is correct |
55 |
Correct |
67 ms |
1620 KB |
Output is correct |
56 |
Correct |
52 ms |
1116 KB |
Output is correct |
57 |
Correct |
67 ms |
1620 KB |
Output is correct |
58 |
Correct |
62 ms |
1108 KB |
Output is correct |
59 |
Correct |
62 ms |
1360 KB |
Output is correct |
60 |
Correct |
63 ms |
1116 KB |
Output is correct |
61 |
Correct |
63 ms |
1364 KB |
Output is correct |
62 |
Correct |
60 ms |
1364 KB |
Output is correct |
63 |
Correct |
60 ms |
1616 KB |
Output is correct |
64 |
Correct |
59 ms |
1600 KB |
Output is correct |
65 |
Correct |
53 ms |
1116 KB |
Output is correct |
66 |
Correct |
53 ms |
948 KB |
Output is correct |
67 |
Correct |
73 ms |
1364 KB |
Output is correct |
68 |
Correct |
26 ms |
860 KB |
Output is correct |
69 |
Correct |
113 ms |
2268 KB |
Output is correct |
70 |
Correct |
104 ms |
1616 KB |
Output is correct |
71 |
Correct |
100 ms |
1708 KB |
Output is correct |
72 |
Correct |
94 ms |
1364 KB |
Output is correct |
73 |
Correct |
95 ms |
1368 KB |
Output is correct |
74 |
Correct |
120 ms |
2312 KB |
Output is correct |
75 |
Correct |
105 ms |
2120 KB |
Output is correct |
76 |
Correct |
118 ms |
2384 KB |
Output is correct |
77 |
Correct |
118 ms |
2388 KB |
Output is correct |