#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int N = 505, M = 260010;
int n;
int a[N];
int S;
int DP[M];
int dp[M];
int ans[M], ANS[M];
int V[M], np;
int main()
{
cin>>n;
for (int i = 1; i <= n; i++){
cin>>a[i];
S += a[i];
}
sort (a + 1, a + n + 1);
bool ok = 0;
for (int i = 2; i <= n; i++)
if ((a[i] - a[i - 1]) % 2 == 1)
ok = 1;
if (S % 2 == 1)
ok = 1;
if (ok){
cout<<0<<endl;
return 0;
}
DP[0] = 1;
for (int i = 1; i <= n; i++){
for (int j = S; j >= a[i]; j--){
DP[j] += DP[j - a[i]];
}
}
if (DP[S / 2] == 0){
cout<<0<<endl;
return 0;
}
for (int I = 1; I <= n; ++I){
for (int i = 0; i <= S; ++i){
dp[i] = DP[i];
ans[abs (S - 2 * i - a[I])] = 0;
}
for (int i = 0; i <= S; ++i){
if (i >= a[I]){
dp[i] -= dp[i - a[I]];
}
int x = abs (S - a[I] - 2 * i);
if (dp[i] && ans[x] == 0){
ans[x] = 1;
ANS[x]++;
}
}
}
np = 0;
for (int i = 0; i <= S; i++)
if (ANS[i] == n)
V[np++] = i;
cout<<np<<endl;
for (int i = 0; i < np; i++)
cout<<V[i]<<" ";
cout<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
468 KB |
Output is correct |
25 |
Correct |
6 ms |
504 KB |
Output is correct |
26 |
Correct |
7 ms |
504 KB |
Output is correct |
27 |
Correct |
6 ms |
504 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
476 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
6 ms |
504 KB |
Output is correct |
36 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
468 KB |
Output is correct |
25 |
Correct |
6 ms |
504 KB |
Output is correct |
26 |
Correct |
7 ms |
504 KB |
Output is correct |
27 |
Correct |
6 ms |
504 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
476 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
6 ms |
504 KB |
Output is correct |
36 |
Correct |
4 ms |
376 KB |
Output is correct |
37 |
Correct |
22 ms |
760 KB |
Output is correct |
38 |
Correct |
22 ms |
740 KB |
Output is correct |
39 |
Correct |
57 ms |
1272 KB |
Output is correct |
40 |
Correct |
47 ms |
1016 KB |
Output is correct |
41 |
Correct |
81 ms |
1560 KB |
Output is correct |
42 |
Correct |
41 ms |
1016 KB |
Output is correct |
43 |
Correct |
73 ms |
1528 KB |
Output is correct |
44 |
Correct |
74 ms |
1400 KB |
Output is correct |
45 |
Correct |
73 ms |
1528 KB |
Output is correct |
46 |
Correct |
39 ms |
880 KB |
Output is correct |
47 |
Correct |
45 ms |
1016 KB |
Output is correct |
48 |
Correct |
78 ms |
1528 KB |
Output is correct |
49 |
Correct |
67 ms |
1372 KB |
Output is correct |
50 |
Correct |
43 ms |
1020 KB |
Output is correct |
51 |
Correct |
2 ms |
256 KB |
Output is correct |
52 |
Correct |
97 ms |
1784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
468 KB |
Output is correct |
25 |
Correct |
6 ms |
504 KB |
Output is correct |
26 |
Correct |
7 ms |
504 KB |
Output is correct |
27 |
Correct |
6 ms |
504 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
476 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
6 ms |
504 KB |
Output is correct |
36 |
Correct |
4 ms |
376 KB |
Output is correct |
37 |
Correct |
22 ms |
760 KB |
Output is correct |
38 |
Correct |
22 ms |
740 KB |
Output is correct |
39 |
Correct |
57 ms |
1272 KB |
Output is correct |
40 |
Correct |
47 ms |
1016 KB |
Output is correct |
41 |
Correct |
81 ms |
1560 KB |
Output is correct |
42 |
Correct |
41 ms |
1016 KB |
Output is correct |
43 |
Correct |
73 ms |
1528 KB |
Output is correct |
44 |
Correct |
74 ms |
1400 KB |
Output is correct |
45 |
Correct |
73 ms |
1528 KB |
Output is correct |
46 |
Correct |
39 ms |
880 KB |
Output is correct |
47 |
Correct |
45 ms |
1016 KB |
Output is correct |
48 |
Correct |
78 ms |
1528 KB |
Output is correct |
49 |
Correct |
67 ms |
1372 KB |
Output is correct |
50 |
Correct |
43 ms |
1020 KB |
Output is correct |
51 |
Correct |
2 ms |
256 KB |
Output is correct |
52 |
Correct |
97 ms |
1784 KB |
Output is correct |
53 |
Correct |
72 ms |
1272 KB |
Output is correct |
54 |
Correct |
104 ms |
1420 KB |
Output is correct |
55 |
Correct |
196 ms |
2640 KB |
Output is correct |
56 |
Correct |
88 ms |
1532 KB |
Output is correct |
57 |
Correct |
210 ms |
2712 KB |
Output is correct |
58 |
Correct |
115 ms |
1640 KB |
Output is correct |
59 |
Correct |
140 ms |
1884 KB |
Output is correct |
60 |
Correct |
2 ms |
256 KB |
Output is correct |
61 |
Correct |
161 ms |
2040 KB |
Output is correct |
62 |
Correct |
156 ms |
2304 KB |
Output is correct |
63 |
Correct |
171 ms |
2428 KB |
Output is correct |
64 |
Correct |
167 ms |
2424 KB |
Output is correct |
65 |
Correct |
71 ms |
1272 KB |
Output is correct |
66 |
Correct |
71 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
468 KB |
Output is correct |
25 |
Correct |
6 ms |
504 KB |
Output is correct |
26 |
Correct |
7 ms |
504 KB |
Output is correct |
27 |
Correct |
6 ms |
504 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
476 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
6 ms |
504 KB |
Output is correct |
36 |
Correct |
4 ms |
376 KB |
Output is correct |
37 |
Correct |
22 ms |
760 KB |
Output is correct |
38 |
Correct |
22 ms |
740 KB |
Output is correct |
39 |
Correct |
57 ms |
1272 KB |
Output is correct |
40 |
Correct |
47 ms |
1016 KB |
Output is correct |
41 |
Correct |
81 ms |
1560 KB |
Output is correct |
42 |
Correct |
41 ms |
1016 KB |
Output is correct |
43 |
Correct |
73 ms |
1528 KB |
Output is correct |
44 |
Correct |
74 ms |
1400 KB |
Output is correct |
45 |
Correct |
73 ms |
1528 KB |
Output is correct |
46 |
Correct |
39 ms |
880 KB |
Output is correct |
47 |
Correct |
45 ms |
1016 KB |
Output is correct |
48 |
Correct |
78 ms |
1528 KB |
Output is correct |
49 |
Correct |
67 ms |
1372 KB |
Output is correct |
50 |
Correct |
43 ms |
1020 KB |
Output is correct |
51 |
Correct |
2 ms |
256 KB |
Output is correct |
52 |
Correct |
97 ms |
1784 KB |
Output is correct |
53 |
Correct |
72 ms |
1272 KB |
Output is correct |
54 |
Correct |
104 ms |
1420 KB |
Output is correct |
55 |
Correct |
196 ms |
2640 KB |
Output is correct |
56 |
Correct |
88 ms |
1532 KB |
Output is correct |
57 |
Correct |
210 ms |
2712 KB |
Output is correct |
58 |
Correct |
115 ms |
1640 KB |
Output is correct |
59 |
Correct |
140 ms |
1884 KB |
Output is correct |
60 |
Correct |
2 ms |
256 KB |
Output is correct |
61 |
Correct |
161 ms |
2040 KB |
Output is correct |
62 |
Correct |
156 ms |
2304 KB |
Output is correct |
63 |
Correct |
171 ms |
2428 KB |
Output is correct |
64 |
Correct |
167 ms |
2424 KB |
Output is correct |
65 |
Correct |
71 ms |
1272 KB |
Output is correct |
66 |
Correct |
71 ms |
1272 KB |
Output is correct |
67 |
Correct |
166 ms |
2024 KB |
Output is correct |
68 |
Correct |
41 ms |
856 KB |
Output is correct |
69 |
Correct |
540 ms |
4768 KB |
Output is correct |
70 |
Correct |
334 ms |
3152 KB |
Output is correct |
71 |
Correct |
317 ms |
2936 KB |
Output is correct |
72 |
Correct |
2 ms |
256 KB |
Output is correct |
73 |
Correct |
2 ms |
376 KB |
Output is correct |
74 |
Correct |
581 ms |
5040 KB |
Output is correct |
75 |
Correct |
440 ms |
3964 KB |
Output is correct |
76 |
Correct |
606 ms |
5308 KB |
Output is correct |
77 |
Correct |
598 ms |
5240 KB |
Output is correct |