#include <bits/stdc++.h>
using namespace std;
const int maxn = 507;
int D[maxn * maxn], a[maxn];
int main()
{
// freopen("TEST.INP", "r", stdin);
// freopen("TEST.OUT", "w", stdout);
int n, sum = 0;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i], sum += a[i];
D[0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = sum / 2; j >= 0; --j)
D[j + a[i]] += D[j];
if ((sum & 1) || !D[sum / 2]) return cout << 0, 0;
vector <int> cnt(sum + 1);
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j <= sum; ++j)
D[j + a[i]] -= D[j];
for (int j = 1; j <= sum; ++j)
{
int val = sum - a[i] + j;
cnt[j] += (val / 2 - j >= 0 && 1 - val % 2 && D[val / 2 - j]);
}
for (int j = sum / 2; j >= 0; --j)
D[j + a[i]] += D[j];
}
vector <int> ans;
for (int i = 1; i <= sum; ++i)
if (cnt[i] == n) ans.push_back(i);
cout << (int)ans.size() << '\n';
for (int x: ans) cout << x << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
7 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
544 KB |
Output is correct |
26 |
Correct |
8 ms |
512 KB |
Output is correct |
27 |
Correct |
7 ms |
384 KB |
Output is correct |
28 |
Correct |
7 ms |
384 KB |
Output is correct |
29 |
Correct |
7 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
7 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Correct |
7 ms |
384 KB |
Output is correct |
34 |
Correct |
7 ms |
384 KB |
Output is correct |
35 |
Correct |
7 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
7 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
544 KB |
Output is correct |
26 |
Correct |
8 ms |
512 KB |
Output is correct |
27 |
Correct |
7 ms |
384 KB |
Output is correct |
28 |
Correct |
7 ms |
384 KB |
Output is correct |
29 |
Correct |
7 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
7 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Correct |
7 ms |
384 KB |
Output is correct |
34 |
Correct |
7 ms |
384 KB |
Output is correct |
35 |
Correct |
7 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
384 KB |
Output is correct |
37 |
Correct |
17 ms |
640 KB |
Output is correct |
38 |
Correct |
17 ms |
672 KB |
Output is correct |
39 |
Correct |
50 ms |
768 KB |
Output is correct |
40 |
Correct |
31 ms |
768 KB |
Output is correct |
41 |
Correct |
61 ms |
896 KB |
Output is correct |
42 |
Correct |
28 ms |
768 KB |
Output is correct |
43 |
Correct |
46 ms |
1144 KB |
Output is correct |
44 |
Correct |
49 ms |
1144 KB |
Output is correct |
45 |
Correct |
48 ms |
1144 KB |
Output is correct |
46 |
Correct |
29 ms |
512 KB |
Output is correct |
47 |
Correct |
30 ms |
760 KB |
Output is correct |
48 |
Correct |
51 ms |
1144 KB |
Output is correct |
49 |
Correct |
50 ms |
888 KB |
Output is correct |
50 |
Correct |
30 ms |
760 KB |
Output is correct |
51 |
Correct |
8 ms |
384 KB |
Output is correct |
52 |
Correct |
62 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
7 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
544 KB |
Output is correct |
26 |
Correct |
8 ms |
512 KB |
Output is correct |
27 |
Correct |
7 ms |
384 KB |
Output is correct |
28 |
Correct |
7 ms |
384 KB |
Output is correct |
29 |
Correct |
7 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
7 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Correct |
7 ms |
384 KB |
Output is correct |
34 |
Correct |
7 ms |
384 KB |
Output is correct |
35 |
Correct |
7 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
384 KB |
Output is correct |
37 |
Correct |
17 ms |
640 KB |
Output is correct |
38 |
Correct |
17 ms |
672 KB |
Output is correct |
39 |
Correct |
50 ms |
768 KB |
Output is correct |
40 |
Correct |
31 ms |
768 KB |
Output is correct |
41 |
Correct |
61 ms |
896 KB |
Output is correct |
42 |
Correct |
28 ms |
768 KB |
Output is correct |
43 |
Correct |
46 ms |
1144 KB |
Output is correct |
44 |
Correct |
49 ms |
1144 KB |
Output is correct |
45 |
Correct |
48 ms |
1144 KB |
Output is correct |
46 |
Correct |
29 ms |
512 KB |
Output is correct |
47 |
Correct |
30 ms |
760 KB |
Output is correct |
48 |
Correct |
51 ms |
1144 KB |
Output is correct |
49 |
Correct |
50 ms |
888 KB |
Output is correct |
50 |
Correct |
30 ms |
760 KB |
Output is correct |
51 |
Correct |
8 ms |
384 KB |
Output is correct |
52 |
Correct |
62 ms |
1272 KB |
Output is correct |
53 |
Correct |
46 ms |
1020 KB |
Output is correct |
54 |
Correct |
63 ms |
1144 KB |
Output is correct |
55 |
Correct |
129 ms |
1780 KB |
Output is correct |
56 |
Correct |
58 ms |
1204 KB |
Output is correct |
57 |
Correct |
128 ms |
1908 KB |
Output is correct |
58 |
Correct |
70 ms |
1272 KB |
Output is correct |
59 |
Correct |
89 ms |
1396 KB |
Output is correct |
60 |
Correct |
11 ms |
384 KB |
Output is correct |
61 |
Correct |
95 ms |
1524 KB |
Output is correct |
62 |
Correct |
98 ms |
1652 KB |
Output is correct |
63 |
Correct |
105 ms |
1780 KB |
Output is correct |
64 |
Correct |
101 ms |
1688 KB |
Output is correct |
65 |
Correct |
52 ms |
760 KB |
Output is correct |
66 |
Correct |
54 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
7 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
544 KB |
Output is correct |
26 |
Correct |
8 ms |
512 KB |
Output is correct |
27 |
Correct |
7 ms |
384 KB |
Output is correct |
28 |
Correct |
7 ms |
384 KB |
Output is correct |
29 |
Correct |
7 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
7 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Correct |
7 ms |
384 KB |
Output is correct |
34 |
Correct |
7 ms |
384 KB |
Output is correct |
35 |
Correct |
7 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
384 KB |
Output is correct |
37 |
Correct |
17 ms |
640 KB |
Output is correct |
38 |
Correct |
17 ms |
672 KB |
Output is correct |
39 |
Correct |
50 ms |
768 KB |
Output is correct |
40 |
Correct |
31 ms |
768 KB |
Output is correct |
41 |
Correct |
61 ms |
896 KB |
Output is correct |
42 |
Correct |
28 ms |
768 KB |
Output is correct |
43 |
Correct |
46 ms |
1144 KB |
Output is correct |
44 |
Correct |
49 ms |
1144 KB |
Output is correct |
45 |
Correct |
48 ms |
1144 KB |
Output is correct |
46 |
Correct |
29 ms |
512 KB |
Output is correct |
47 |
Correct |
30 ms |
760 KB |
Output is correct |
48 |
Correct |
51 ms |
1144 KB |
Output is correct |
49 |
Correct |
50 ms |
888 KB |
Output is correct |
50 |
Correct |
30 ms |
760 KB |
Output is correct |
51 |
Correct |
8 ms |
384 KB |
Output is correct |
52 |
Correct |
62 ms |
1272 KB |
Output is correct |
53 |
Correct |
46 ms |
1020 KB |
Output is correct |
54 |
Correct |
63 ms |
1144 KB |
Output is correct |
55 |
Correct |
129 ms |
1780 KB |
Output is correct |
56 |
Correct |
58 ms |
1204 KB |
Output is correct |
57 |
Correct |
128 ms |
1908 KB |
Output is correct |
58 |
Correct |
70 ms |
1272 KB |
Output is correct |
59 |
Correct |
89 ms |
1396 KB |
Output is correct |
60 |
Correct |
11 ms |
384 KB |
Output is correct |
61 |
Correct |
95 ms |
1524 KB |
Output is correct |
62 |
Correct |
98 ms |
1652 KB |
Output is correct |
63 |
Correct |
105 ms |
1780 KB |
Output is correct |
64 |
Correct |
101 ms |
1688 KB |
Output is correct |
65 |
Correct |
52 ms |
760 KB |
Output is correct |
66 |
Correct |
54 ms |
888 KB |
Output is correct |
67 |
Correct |
101 ms |
1396 KB |
Output is correct |
68 |
Correct |
21 ms |
512 KB |
Output is correct |
69 |
Correct |
320 ms |
3184 KB |
Output is correct |
70 |
Correct |
200 ms |
2164 KB |
Output is correct |
71 |
Correct |
189 ms |
2036 KB |
Output is correct |
72 |
Correct |
184 ms |
1280 KB |
Output is correct |
73 |
Correct |
188 ms |
1400 KB |
Output is correct |
74 |
Correct |
336 ms |
3312 KB |
Output is correct |
75 |
Correct |
265 ms |
2800 KB |
Output is correct |
76 |
Correct |
367 ms |
3440 KB |
Output is correct |
77 |
Correct |
363 ms |
3568 KB |
Output is correct |