#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <bitset>
#include <vector>
typedef long long llong;
const int MAXS = 250000 + 10;
const int MAXN = 500 + 10;
const int MOD = 1e9 + 13;
int n;
int a[MAXN];
int dp[MAXS];
int copy[MAXS];
int cnt[MAXS];
void solve()
{
int sum = 0;
dp[0] = 1;
for (int i = 1 ; i <= n ; ++i)
{
sum += a[i];
for (int j = MAXS - 1 ; j >= a[i] ; --j)
{
dp[j] += dp[j - a[i]];
if (dp[j] >= MOD) dp[j] -= MOD;
}
}
if ((sum & 1) || (!dp[sum / 2]))
{
std::cout << "0\n\n";
return;
}
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 1 ; j < MAXS ; ++j)
{
copy[j] = dp[j];
}
for (int j = 0 ; j + a[i] < MAXS ; ++j)
{
dp[j + a[i]] -= dp[j];
if (dp[j + a[i]] < 0)
{
dp[j + a[i]] += MOD;
}
}
for (int j = 0 ; j < MAXS && sum - a[i] - 2 * j > 0 ; ++j)
{
if (dp[j] != 0)
{
cnt[sum - a[i] - 2 * j]++;
}
}
for (int j = 1 ; j < MAXS ; ++j)
{
dp[j] = copy[j];
}
}
int count = 0;
for (int i = 1 ; i < MAXS ; ++i)
{
count += (cnt[i] == n);
}
std::cout << count << '\n';
for (int i = 1 ; i < MAXS ; ++i)
{
if (cnt[i] == n)
{
std::cout << i << ' ';
}
}
std::cout << '\n';
}
void input()
{
std::cin >> n;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3164 KB |
Output is correct |
2 |
Correct |
4 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
3164 KB |
Output is correct |
6 |
Correct |
6 ms |
3160 KB |
Output is correct |
7 |
Correct |
4 ms |
3164 KB |
Output is correct |
8 |
Correct |
7 ms |
3164 KB |
Output is correct |
9 |
Correct |
6 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3164 KB |
Output is correct |
2 |
Correct |
4 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
3164 KB |
Output is correct |
6 |
Correct |
6 ms |
3160 KB |
Output is correct |
7 |
Correct |
4 ms |
3164 KB |
Output is correct |
8 |
Correct |
7 ms |
3164 KB |
Output is correct |
9 |
Correct |
6 ms |
3164 KB |
Output is correct |
10 |
Correct |
14 ms |
3160 KB |
Output is correct |
11 |
Correct |
17 ms |
3208 KB |
Output is correct |
12 |
Correct |
15 ms |
3160 KB |
Output is correct |
13 |
Correct |
14 ms |
3164 KB |
Output is correct |
14 |
Correct |
14 ms |
3220 KB |
Output is correct |
15 |
Correct |
18 ms |
3164 KB |
Output is correct |
16 |
Correct |
17 ms |
3164 KB |
Output is correct |
17 |
Correct |
10 ms |
3216 KB |
Output is correct |
18 |
Correct |
12 ms |
3164 KB |
Output is correct |
19 |
Correct |
13 ms |
3164 KB |
Output is correct |
20 |
Correct |
14 ms |
3212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3164 KB |
Output is correct |
2 |
Correct |
4 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
3164 KB |
Output is correct |
6 |
Correct |
6 ms |
3160 KB |
Output is correct |
7 |
Correct |
4 ms |
3164 KB |
Output is correct |
8 |
Correct |
7 ms |
3164 KB |
Output is correct |
9 |
Correct |
6 ms |
3164 KB |
Output is correct |
10 |
Correct |
14 ms |
3160 KB |
Output is correct |
11 |
Correct |
17 ms |
3208 KB |
Output is correct |
12 |
Correct |
15 ms |
3160 KB |
Output is correct |
13 |
Correct |
14 ms |
3164 KB |
Output is correct |
14 |
Correct |
14 ms |
3220 KB |
Output is correct |
15 |
Correct |
18 ms |
3164 KB |
Output is correct |
16 |
Correct |
17 ms |
3164 KB |
Output is correct |
17 |
Correct |
10 ms |
3216 KB |
Output is correct |
18 |
Correct |
12 ms |
3164 KB |
Output is correct |
19 |
Correct |
13 ms |
3164 KB |
Output is correct |
20 |
Correct |
14 ms |
3212 KB |
Output is correct |
21 |
Correct |
31 ms |
3464 KB |
Output is correct |
22 |
Correct |
34 ms |
3208 KB |
Output is correct |
23 |
Correct |
24 ms |
3164 KB |
Output is correct |
24 |
Correct |
48 ms |
3192 KB |
Output is correct |
25 |
Correct |
43 ms |
3160 KB |
Output is correct |
26 |
Correct |
46 ms |
3236 KB |
Output is correct |
27 |
Correct |
48 ms |
3164 KB |
Output is correct |
28 |
Correct |
47 ms |
3212 KB |
Output is correct |
29 |
Correct |
45 ms |
3216 KB |
Output is correct |
30 |
Correct |
46 ms |
3164 KB |
Output is correct |
31 |
Correct |
45 ms |
3220 KB |
Output is correct |
32 |
Correct |
46 ms |
3164 KB |
Output is correct |
33 |
Correct |
46 ms |
3360 KB |
Output is correct |
34 |
Correct |
45 ms |
3240 KB |
Output is correct |
35 |
Correct |
45 ms |
3164 KB |
Output is correct |
36 |
Correct |
50 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3164 KB |
Output is correct |
2 |
Correct |
4 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
3164 KB |
Output is correct |
6 |
Correct |
6 ms |
3160 KB |
Output is correct |
7 |
Correct |
4 ms |
3164 KB |
Output is correct |
8 |
Correct |
7 ms |
3164 KB |
Output is correct |
9 |
Correct |
6 ms |
3164 KB |
Output is correct |
10 |
Correct |
14 ms |
3160 KB |
Output is correct |
11 |
Correct |
17 ms |
3208 KB |
Output is correct |
12 |
Correct |
15 ms |
3160 KB |
Output is correct |
13 |
Correct |
14 ms |
3164 KB |
Output is correct |
14 |
Correct |
14 ms |
3220 KB |
Output is correct |
15 |
Correct |
18 ms |
3164 KB |
Output is correct |
16 |
Correct |
17 ms |
3164 KB |
Output is correct |
17 |
Correct |
10 ms |
3216 KB |
Output is correct |
18 |
Correct |
12 ms |
3164 KB |
Output is correct |
19 |
Correct |
13 ms |
3164 KB |
Output is correct |
20 |
Correct |
14 ms |
3212 KB |
Output is correct |
21 |
Correct |
31 ms |
3464 KB |
Output is correct |
22 |
Correct |
34 ms |
3208 KB |
Output is correct |
23 |
Correct |
24 ms |
3164 KB |
Output is correct |
24 |
Correct |
48 ms |
3192 KB |
Output is correct |
25 |
Correct |
43 ms |
3160 KB |
Output is correct |
26 |
Correct |
46 ms |
3236 KB |
Output is correct |
27 |
Correct |
48 ms |
3164 KB |
Output is correct |
28 |
Correct |
47 ms |
3212 KB |
Output is correct |
29 |
Correct |
45 ms |
3216 KB |
Output is correct |
30 |
Correct |
46 ms |
3164 KB |
Output is correct |
31 |
Correct |
45 ms |
3220 KB |
Output is correct |
32 |
Correct |
46 ms |
3164 KB |
Output is correct |
33 |
Correct |
46 ms |
3360 KB |
Output is correct |
34 |
Correct |
45 ms |
3240 KB |
Output is correct |
35 |
Correct |
45 ms |
3164 KB |
Output is correct |
36 |
Correct |
50 ms |
3164 KB |
Output is correct |
37 |
Correct |
91 ms |
3208 KB |
Output is correct |
38 |
Correct |
90 ms |
3192 KB |
Output is correct |
39 |
Correct |
115 ms |
3160 KB |
Output is correct |
40 |
Correct |
123 ms |
3408 KB |
Output is correct |
41 |
Correct |
125 ms |
3204 KB |
Output is correct |
42 |
Correct |
114 ms |
3416 KB |
Output is correct |
43 |
Correct |
128 ms |
3372 KB |
Output is correct |
44 |
Correct |
117 ms |
3456 KB |
Output is correct |
45 |
Correct |
116 ms |
3412 KB |
Output is correct |
46 |
Correct |
133 ms |
3164 KB |
Output is correct |
47 |
Correct |
116 ms |
3412 KB |
Output is correct |
48 |
Correct |
121 ms |
3460 KB |
Output is correct |
49 |
Correct |
117 ms |
3164 KB |
Output is correct |
50 |
Correct |
116 ms |
3412 KB |
Output is correct |
51 |
Correct |
51 ms |
3160 KB |
Output is correct |
52 |
Correct |
143 ms |
3372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3164 KB |
Output is correct |
2 |
Correct |
4 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
3164 KB |
Output is correct |
6 |
Correct |
6 ms |
3160 KB |
Output is correct |
7 |
Correct |
4 ms |
3164 KB |
Output is correct |
8 |
Correct |
7 ms |
3164 KB |
Output is correct |
9 |
Correct |
6 ms |
3164 KB |
Output is correct |
10 |
Correct |
14 ms |
3160 KB |
Output is correct |
11 |
Correct |
17 ms |
3208 KB |
Output is correct |
12 |
Correct |
15 ms |
3160 KB |
Output is correct |
13 |
Correct |
14 ms |
3164 KB |
Output is correct |
14 |
Correct |
14 ms |
3220 KB |
Output is correct |
15 |
Correct |
18 ms |
3164 KB |
Output is correct |
16 |
Correct |
17 ms |
3164 KB |
Output is correct |
17 |
Correct |
10 ms |
3216 KB |
Output is correct |
18 |
Correct |
12 ms |
3164 KB |
Output is correct |
19 |
Correct |
13 ms |
3164 KB |
Output is correct |
20 |
Correct |
14 ms |
3212 KB |
Output is correct |
21 |
Correct |
31 ms |
3464 KB |
Output is correct |
22 |
Correct |
34 ms |
3208 KB |
Output is correct |
23 |
Correct |
24 ms |
3164 KB |
Output is correct |
24 |
Correct |
48 ms |
3192 KB |
Output is correct |
25 |
Correct |
43 ms |
3160 KB |
Output is correct |
26 |
Correct |
46 ms |
3236 KB |
Output is correct |
27 |
Correct |
48 ms |
3164 KB |
Output is correct |
28 |
Correct |
47 ms |
3212 KB |
Output is correct |
29 |
Correct |
45 ms |
3216 KB |
Output is correct |
30 |
Correct |
46 ms |
3164 KB |
Output is correct |
31 |
Correct |
45 ms |
3220 KB |
Output is correct |
32 |
Correct |
46 ms |
3164 KB |
Output is correct |
33 |
Correct |
46 ms |
3360 KB |
Output is correct |
34 |
Correct |
45 ms |
3240 KB |
Output is correct |
35 |
Correct |
45 ms |
3164 KB |
Output is correct |
36 |
Correct |
50 ms |
3164 KB |
Output is correct |
37 |
Correct |
91 ms |
3208 KB |
Output is correct |
38 |
Correct |
90 ms |
3192 KB |
Output is correct |
39 |
Correct |
115 ms |
3160 KB |
Output is correct |
40 |
Correct |
123 ms |
3408 KB |
Output is correct |
41 |
Correct |
125 ms |
3204 KB |
Output is correct |
42 |
Correct |
114 ms |
3416 KB |
Output is correct |
43 |
Correct |
128 ms |
3372 KB |
Output is correct |
44 |
Correct |
117 ms |
3456 KB |
Output is correct |
45 |
Correct |
116 ms |
3412 KB |
Output is correct |
46 |
Correct |
133 ms |
3164 KB |
Output is correct |
47 |
Correct |
116 ms |
3412 KB |
Output is correct |
48 |
Correct |
121 ms |
3460 KB |
Output is correct |
49 |
Correct |
117 ms |
3164 KB |
Output is correct |
50 |
Correct |
116 ms |
3412 KB |
Output is correct |
51 |
Correct |
51 ms |
3160 KB |
Output is correct |
52 |
Correct |
143 ms |
3372 KB |
Output is correct |
53 |
Correct |
139 ms |
3448 KB |
Output is correct |
54 |
Correct |
163 ms |
3448 KB |
Output is correct |
55 |
Correct |
173 ms |
3628 KB |
Output is correct |
56 |
Correct |
141 ms |
3408 KB |
Output is correct |
57 |
Correct |
186 ms |
3464 KB |
Output is correct |
58 |
Correct |
166 ms |
3448 KB |
Output is correct |
59 |
Correct |
165 ms |
3412 KB |
Output is correct |
60 |
Correct |
70 ms |
3164 KB |
Output is correct |
61 |
Correct |
169 ms |
3372 KB |
Output is correct |
62 |
Correct |
154 ms |
3408 KB |
Output is correct |
63 |
Correct |
155 ms |
3408 KB |
Output is correct |
64 |
Correct |
151 ms |
3412 KB |
Output is correct |
65 |
Correct |
154 ms |
3372 KB |
Output is correct |
66 |
Correct |
146 ms |
3160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3164 KB |
Output is correct |
2 |
Correct |
4 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
3164 KB |
Output is correct |
6 |
Correct |
6 ms |
3160 KB |
Output is correct |
7 |
Correct |
4 ms |
3164 KB |
Output is correct |
8 |
Correct |
7 ms |
3164 KB |
Output is correct |
9 |
Correct |
6 ms |
3164 KB |
Output is correct |
10 |
Correct |
14 ms |
3160 KB |
Output is correct |
11 |
Correct |
17 ms |
3208 KB |
Output is correct |
12 |
Correct |
15 ms |
3160 KB |
Output is correct |
13 |
Correct |
14 ms |
3164 KB |
Output is correct |
14 |
Correct |
14 ms |
3220 KB |
Output is correct |
15 |
Correct |
18 ms |
3164 KB |
Output is correct |
16 |
Correct |
17 ms |
3164 KB |
Output is correct |
17 |
Correct |
10 ms |
3216 KB |
Output is correct |
18 |
Correct |
12 ms |
3164 KB |
Output is correct |
19 |
Correct |
13 ms |
3164 KB |
Output is correct |
20 |
Correct |
14 ms |
3212 KB |
Output is correct |
21 |
Correct |
31 ms |
3464 KB |
Output is correct |
22 |
Correct |
34 ms |
3208 KB |
Output is correct |
23 |
Correct |
24 ms |
3164 KB |
Output is correct |
24 |
Correct |
48 ms |
3192 KB |
Output is correct |
25 |
Correct |
43 ms |
3160 KB |
Output is correct |
26 |
Correct |
46 ms |
3236 KB |
Output is correct |
27 |
Correct |
48 ms |
3164 KB |
Output is correct |
28 |
Correct |
47 ms |
3212 KB |
Output is correct |
29 |
Correct |
45 ms |
3216 KB |
Output is correct |
30 |
Correct |
46 ms |
3164 KB |
Output is correct |
31 |
Correct |
45 ms |
3220 KB |
Output is correct |
32 |
Correct |
46 ms |
3164 KB |
Output is correct |
33 |
Correct |
46 ms |
3360 KB |
Output is correct |
34 |
Correct |
45 ms |
3240 KB |
Output is correct |
35 |
Correct |
45 ms |
3164 KB |
Output is correct |
36 |
Correct |
50 ms |
3164 KB |
Output is correct |
37 |
Correct |
91 ms |
3208 KB |
Output is correct |
38 |
Correct |
90 ms |
3192 KB |
Output is correct |
39 |
Correct |
115 ms |
3160 KB |
Output is correct |
40 |
Correct |
123 ms |
3408 KB |
Output is correct |
41 |
Correct |
125 ms |
3204 KB |
Output is correct |
42 |
Correct |
114 ms |
3416 KB |
Output is correct |
43 |
Correct |
128 ms |
3372 KB |
Output is correct |
44 |
Correct |
117 ms |
3456 KB |
Output is correct |
45 |
Correct |
116 ms |
3412 KB |
Output is correct |
46 |
Correct |
133 ms |
3164 KB |
Output is correct |
47 |
Correct |
116 ms |
3412 KB |
Output is correct |
48 |
Correct |
121 ms |
3460 KB |
Output is correct |
49 |
Correct |
117 ms |
3164 KB |
Output is correct |
50 |
Correct |
116 ms |
3412 KB |
Output is correct |
51 |
Correct |
51 ms |
3160 KB |
Output is correct |
52 |
Correct |
143 ms |
3372 KB |
Output is correct |
53 |
Correct |
139 ms |
3448 KB |
Output is correct |
54 |
Correct |
163 ms |
3448 KB |
Output is correct |
55 |
Correct |
173 ms |
3628 KB |
Output is correct |
56 |
Correct |
141 ms |
3408 KB |
Output is correct |
57 |
Correct |
186 ms |
3464 KB |
Output is correct |
58 |
Correct |
166 ms |
3448 KB |
Output is correct |
59 |
Correct |
165 ms |
3412 KB |
Output is correct |
60 |
Correct |
70 ms |
3164 KB |
Output is correct |
61 |
Correct |
169 ms |
3372 KB |
Output is correct |
62 |
Correct |
154 ms |
3408 KB |
Output is correct |
63 |
Correct |
155 ms |
3408 KB |
Output is correct |
64 |
Correct |
151 ms |
3412 KB |
Output is correct |
65 |
Correct |
154 ms |
3372 KB |
Output is correct |
66 |
Correct |
146 ms |
3160 KB |
Output is correct |
67 |
Correct |
191 ms |
3372 KB |
Output is correct |
68 |
Correct |
102 ms |
3408 KB |
Output is correct |
69 |
Correct |
261 ms |
3924 KB |
Output is correct |
70 |
Correct |
250 ms |
3788 KB |
Output is correct |
71 |
Correct |
256 ms |
3640 KB |
Output is correct |
72 |
Correct |
242 ms |
3164 KB |
Output is correct |
73 |
Correct |
244 ms |
3376 KB |
Output is correct |
74 |
Correct |
267 ms |
4104 KB |
Output is correct |
75 |
Correct |
249 ms |
3716 KB |
Output is correct |
76 |
Correct |
275 ms |
3884 KB |
Output is correct |
77 |
Correct |
265 ms |
3888 KB |
Output is correct |