#include<bits/stdc++.h>
using namespace std;
const int maxN = 500 + 5;
const int bsSize = (maxN * maxN + 10) / 2;
int n;
int a[maxN];
int cnt[maxN];
bitset<bsSize> dp[2][maxN], pre;
int main() {
cin >> n;
int sum = 0;
int gc = 0;
for (int i = 1; i<=n; i++) {
cin >> a[i];
gc = __gcd(a[i], gc);
}
for (int i = 1; i<=n; i++) {
a[i]/=gc;
if ((a[i] & 1) == 0) {
printf("0\n");
return 0;
}
if (cnt[a[i]] == 0) cnt[a[i]] = i;
sum+=a[i];
}
if (sum & 1) {
printf("0\n");
return 0;
}
for (int i = 1; i <= n + 1; i++) {
dp[0][i].set(0);
}
for (int i = 1; i<=n; i++) {
bool updated = false;
for (int j = 1; j <= n + 1; j++) {
if (j<= n && cnt[a[j]] != j) continue;
if (i == j) {
dp[i&1][j] = dp[(i&1) ^ 1][j];
} else {
if (updated) {
dp[i&1][j] = pre;
} else {
dp[i&1][j] = dp[(i&1) ^ 1][j] | (dp[(i&1) ^ 1][j] << a[i]);
if (i < j && !updated) {
pre = dp[i&1][j];
updated = true;
}
}
}
}
}
if (dp[n&1][n + 1][sum/2] == 0) {
printf("0\n");
return 0;
}
vector<int> ans;
for (int i = 1; i <= sum; i+=2) {
bool ok = true;
for (int j = 1; j<= n; j++) {
if (cnt[a[j]] != j) continue;
int totSum = sum - a[j] + i;
if (totSum % 2 == 1) ok = false;
int val = sum - totSum/2 - a[j];
if (val < 0) ok = false;
if (ok && dp[n&1][j][val] == 0) ok = false;
}
if (ok) ans.push_back(i);
}
cout << ans.size() << endl;
for (int i:ans) {
cout << i * gc << " ";
}
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
8 ms |
1620 KB |
Output is correct |
22 |
Correct |
10 ms |
1796 KB |
Output is correct |
23 |
Correct |
5 ms |
1364 KB |
Output is correct |
24 |
Correct |
15 ms |
2004 KB |
Output is correct |
25 |
Correct |
4 ms |
980 KB |
Output is correct |
26 |
Correct |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
11 ms |
1556 KB |
Output is correct |
32 |
Correct |
15 ms |
2076 KB |
Output is correct |
33 |
Correct |
2 ms |
724 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
17 ms |
2248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
8 ms |
1620 KB |
Output is correct |
22 |
Correct |
10 ms |
1796 KB |
Output is correct |
23 |
Correct |
5 ms |
1364 KB |
Output is correct |
24 |
Correct |
15 ms |
2004 KB |
Output is correct |
25 |
Correct |
4 ms |
980 KB |
Output is correct |
26 |
Correct |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
11 ms |
1556 KB |
Output is correct |
32 |
Correct |
15 ms |
2076 KB |
Output is correct |
33 |
Correct |
2 ms |
724 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
17 ms |
2248 KB |
Output is correct |
37 |
Correct |
38 ms |
2636 KB |
Output is correct |
38 |
Correct |
40 ms |
2820 KB |
Output is correct |
39 |
Correct |
3 ms |
1364 KB |
Output is correct |
40 |
Correct |
128 ms |
5504 KB |
Output is correct |
41 |
Correct |
4 ms |
1492 KB |
Output is correct |
42 |
Correct |
104 ms |
4756 KB |
Output is correct |
43 |
Correct |
36 ms |
2516 KB |
Output is correct |
44 |
Correct |
33 ms |
2436 KB |
Output is correct |
45 |
Correct |
40 ms |
2516 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
115 ms |
4680 KB |
Output is correct |
48 |
Correct |
14 ms |
1876 KB |
Output is correct |
49 |
Correct |
10 ms |
1488 KB |
Output is correct |
50 |
Correct |
107 ms |
5108 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
22 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
8 ms |
1620 KB |
Output is correct |
22 |
Correct |
10 ms |
1796 KB |
Output is correct |
23 |
Correct |
5 ms |
1364 KB |
Output is correct |
24 |
Correct |
15 ms |
2004 KB |
Output is correct |
25 |
Correct |
4 ms |
980 KB |
Output is correct |
26 |
Correct |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
11 ms |
1556 KB |
Output is correct |
32 |
Correct |
15 ms |
2076 KB |
Output is correct |
33 |
Correct |
2 ms |
724 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
17 ms |
2248 KB |
Output is correct |
37 |
Correct |
38 ms |
2636 KB |
Output is correct |
38 |
Correct |
40 ms |
2820 KB |
Output is correct |
39 |
Correct |
3 ms |
1364 KB |
Output is correct |
40 |
Correct |
128 ms |
5504 KB |
Output is correct |
41 |
Correct |
4 ms |
1492 KB |
Output is correct |
42 |
Correct |
104 ms |
4756 KB |
Output is correct |
43 |
Correct |
36 ms |
2516 KB |
Output is correct |
44 |
Correct |
33 ms |
2436 KB |
Output is correct |
45 |
Correct |
40 ms |
2516 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
115 ms |
4680 KB |
Output is correct |
48 |
Correct |
14 ms |
1876 KB |
Output is correct |
49 |
Correct |
10 ms |
1488 KB |
Output is correct |
50 |
Correct |
107 ms |
5108 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
22 ms |
2132 KB |
Output is correct |
53 |
Correct |
122 ms |
5252 KB |
Output is correct |
54 |
Correct |
187 ms |
5604 KB |
Output is correct |
55 |
Correct |
45 ms |
2784 KB |
Output is correct |
56 |
Correct |
171 ms |
5784 KB |
Output is correct |
57 |
Correct |
45 ms |
2904 KB |
Output is correct |
58 |
Correct |
215 ms |
7252 KB |
Output is correct |
59 |
Correct |
140 ms |
5168 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
146 ms |
5184 KB |
Output is correct |
62 |
Correct |
90 ms |
3800 KB |
Output is correct |
63 |
Correct |
53 ms |
2952 KB |
Output is correct |
64 |
Correct |
52 ms |
2944 KB |
Output is correct |
65 |
Correct |
13 ms |
1912 KB |
Output is correct |
66 |
Correct |
47 ms |
2676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
8 ms |
1620 KB |
Output is correct |
22 |
Correct |
10 ms |
1796 KB |
Output is correct |
23 |
Correct |
5 ms |
1364 KB |
Output is correct |
24 |
Correct |
15 ms |
2004 KB |
Output is correct |
25 |
Correct |
4 ms |
980 KB |
Output is correct |
26 |
Correct |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
11 ms |
1556 KB |
Output is correct |
32 |
Correct |
15 ms |
2076 KB |
Output is correct |
33 |
Correct |
2 ms |
724 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
17 ms |
2248 KB |
Output is correct |
37 |
Correct |
38 ms |
2636 KB |
Output is correct |
38 |
Correct |
40 ms |
2820 KB |
Output is correct |
39 |
Correct |
3 ms |
1364 KB |
Output is correct |
40 |
Correct |
128 ms |
5504 KB |
Output is correct |
41 |
Correct |
4 ms |
1492 KB |
Output is correct |
42 |
Correct |
104 ms |
4756 KB |
Output is correct |
43 |
Correct |
36 ms |
2516 KB |
Output is correct |
44 |
Correct |
33 ms |
2436 KB |
Output is correct |
45 |
Correct |
40 ms |
2516 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
115 ms |
4680 KB |
Output is correct |
48 |
Correct |
14 ms |
1876 KB |
Output is correct |
49 |
Correct |
10 ms |
1488 KB |
Output is correct |
50 |
Correct |
107 ms |
5108 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
22 ms |
2132 KB |
Output is correct |
53 |
Correct |
122 ms |
5252 KB |
Output is correct |
54 |
Correct |
187 ms |
5604 KB |
Output is correct |
55 |
Correct |
45 ms |
2784 KB |
Output is correct |
56 |
Correct |
171 ms |
5784 KB |
Output is correct |
57 |
Correct |
45 ms |
2904 KB |
Output is correct |
58 |
Correct |
215 ms |
7252 KB |
Output is correct |
59 |
Correct |
140 ms |
5168 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
146 ms |
5184 KB |
Output is correct |
62 |
Correct |
90 ms |
3800 KB |
Output is correct |
63 |
Correct |
53 ms |
2952 KB |
Output is correct |
64 |
Correct |
52 ms |
2944 KB |
Output is correct |
65 |
Correct |
13 ms |
1912 KB |
Output is correct |
66 |
Correct |
47 ms |
2676 KB |
Output is correct |
67 |
Correct |
251 ms |
8748 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
111 ms |
4308 KB |
Output is correct |
70 |
Correct |
531 ms |
10312 KB |
Output is correct |
71 |
Correct |
535 ms |
10348 KB |
Output is correct |
72 |
Correct |
1 ms |
344 KB |
Output is correct |
73 |
Correct |
1 ms |
340 KB |
Output is correct |
74 |
Correct |
162 ms |
5144 KB |
Output is correct |
75 |
Correct |
337 ms |
7624 KB |
Output is correct |
76 |
Correct |
73 ms |
3948 KB |
Output is correct |
77 |
Correct |
126 ms |
4436 KB |
Output is correct |