#include<bits/stdc++.h>
using namespace std;
const int maxN = 270 + 5;
const int bsSize = maxN * maxN + 10;
int n;
int a[maxN];
bitset<bsSize> dp[2][maxN];
int main() {
cin >> n;
int sum = 0;
for (int i = 1; i<=n; i++) {
cin >> a[i];
sum+=a[i];
}
for (int i = 1; i <= n + 1; i++) {
dp[0][i].set(0);
}
for (int i = 1; i<=n; i++) {
for (int j = 1; j <= n + 1; j++) {
if (i == j) {
dp[i&1][j] = dp[(i&1) ^ 1][j];
} else {
dp[i&1][j] = dp[(i&1) ^ 1][j] | (dp[(i&1) ^ 1][j] << a[i]);
}
}
for (int j = 1; j<= n + 1; j++) {
dp[(i - 1)&1][j].reset();
}
}
if (dp[n&1][n + 1][sum/2] == 0) {
printf("0\n");
return 0;
}
vector<int> ans;
for (int i = 1; i <= sum; i++) {
bool ok = true;
for (int j = 1; j<= n; j++) {
int totSum = sum - a[j] + i;
if (totSum % 2 == 1) ok = false;
if (dp[n&1][j][totSum/2] == 0) ok = false;
}
if (ok) ans.push_back(i);
}
cout << ans.size() << endl;
for (int i:ans) {
cout << i << " ";
}
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
916 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
852 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
916 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
852 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
852 KB |
Output is correct |
21 |
Correct |
14 ms |
1492 KB |
Output is correct |
22 |
Correct |
18 ms |
1620 KB |
Output is correct |
23 |
Correct |
10 ms |
1276 KB |
Output is correct |
24 |
Correct |
29 ms |
2004 KB |
Output is correct |
25 |
Correct |
30 ms |
2080 KB |
Output is correct |
26 |
Correct |
33 ms |
2196 KB |
Output is correct |
27 |
Correct |
33 ms |
2132 KB |
Output is correct |
28 |
Correct |
35 ms |
2132 KB |
Output is correct |
29 |
Correct |
38 ms |
2176 KB |
Output is correct |
30 |
Correct |
33 ms |
2132 KB |
Output is correct |
31 |
Correct |
33 ms |
2192 KB |
Output is correct |
32 |
Correct |
31 ms |
2132 KB |
Output is correct |
33 |
Correct |
32 ms |
2132 KB |
Output is correct |
34 |
Correct |
33 ms |
2132 KB |
Output is correct |
35 |
Correct |
36 ms |
2132 KB |
Output is correct |
36 |
Correct |
40 ms |
2184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
916 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
852 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
852 KB |
Output is correct |
21 |
Correct |
14 ms |
1492 KB |
Output is correct |
22 |
Correct |
18 ms |
1620 KB |
Output is correct |
23 |
Correct |
10 ms |
1276 KB |
Output is correct |
24 |
Correct |
29 ms |
2004 KB |
Output is correct |
25 |
Correct |
30 ms |
2080 KB |
Output is correct |
26 |
Correct |
33 ms |
2196 KB |
Output is correct |
27 |
Correct |
33 ms |
2132 KB |
Output is correct |
28 |
Correct |
35 ms |
2132 KB |
Output is correct |
29 |
Correct |
38 ms |
2176 KB |
Output is correct |
30 |
Correct |
33 ms |
2132 KB |
Output is correct |
31 |
Correct |
33 ms |
2192 KB |
Output is correct |
32 |
Correct |
31 ms |
2132 KB |
Output is correct |
33 |
Correct |
32 ms |
2132 KB |
Output is correct |
34 |
Correct |
33 ms |
2132 KB |
Output is correct |
35 |
Correct |
36 ms |
2132 KB |
Output is correct |
36 |
Correct |
40 ms |
2184 KB |
Output is correct |
37 |
Correct |
139 ms |
4172 KB |
Output is correct |
38 |
Correct |
132 ms |
4156 KB |
Output is correct |
39 |
Correct |
224 ms |
4912 KB |
Output is correct |
40 |
Correct |
249 ms |
5424 KB |
Output is correct |
41 |
Correct |
299 ms |
5328 KB |
Output is correct |
42 |
Correct |
216 ms |
5068 KB |
Output is correct |
43 |
Correct |
208 ms |
5232 KB |
Output is correct |
44 |
Correct |
217 ms |
5304 KB |
Output is correct |
45 |
Correct |
225 ms |
5344 KB |
Output is correct |
46 |
Correct |
279 ms |
5452 KB |
Output is correct |
47 |
Correct |
207 ms |
5084 KB |
Output is correct |
48 |
Correct |
226 ms |
5212 KB |
Output is correct |
49 |
Correct |
221 ms |
4968 KB |
Output is correct |
50 |
Correct |
213 ms |
5080 KB |
Output is correct |
51 |
Correct |
208 ms |
4956 KB |
Output is correct |
52 |
Correct |
310 ms |
5712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
916 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
852 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
852 KB |
Output is correct |
21 |
Correct |
14 ms |
1492 KB |
Output is correct |
22 |
Correct |
18 ms |
1620 KB |
Output is correct |
23 |
Correct |
10 ms |
1276 KB |
Output is correct |
24 |
Correct |
29 ms |
2004 KB |
Output is correct |
25 |
Correct |
30 ms |
2080 KB |
Output is correct |
26 |
Correct |
33 ms |
2196 KB |
Output is correct |
27 |
Correct |
33 ms |
2132 KB |
Output is correct |
28 |
Correct |
35 ms |
2132 KB |
Output is correct |
29 |
Correct |
38 ms |
2176 KB |
Output is correct |
30 |
Correct |
33 ms |
2132 KB |
Output is correct |
31 |
Correct |
33 ms |
2192 KB |
Output is correct |
32 |
Correct |
31 ms |
2132 KB |
Output is correct |
33 |
Correct |
32 ms |
2132 KB |
Output is correct |
34 |
Correct |
33 ms |
2132 KB |
Output is correct |
35 |
Correct |
36 ms |
2132 KB |
Output is correct |
36 |
Correct |
40 ms |
2184 KB |
Output is correct |
37 |
Correct |
139 ms |
4172 KB |
Output is correct |
38 |
Correct |
132 ms |
4156 KB |
Output is correct |
39 |
Correct |
224 ms |
4912 KB |
Output is correct |
40 |
Correct |
249 ms |
5424 KB |
Output is correct |
41 |
Correct |
299 ms |
5328 KB |
Output is correct |
42 |
Correct |
216 ms |
5068 KB |
Output is correct |
43 |
Correct |
208 ms |
5232 KB |
Output is correct |
44 |
Correct |
217 ms |
5304 KB |
Output is correct |
45 |
Correct |
225 ms |
5344 KB |
Output is correct |
46 |
Correct |
279 ms |
5452 KB |
Output is correct |
47 |
Correct |
207 ms |
5084 KB |
Output is correct |
48 |
Correct |
226 ms |
5212 KB |
Output is correct |
49 |
Correct |
221 ms |
4968 KB |
Output is correct |
50 |
Correct |
213 ms |
5080 KB |
Output is correct |
51 |
Correct |
208 ms |
4956 KB |
Output is correct |
52 |
Correct |
310 ms |
5712 KB |
Output is correct |
53 |
Incorrect |
206 ms |
5144 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
916 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
852 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
852 KB |
Output is correct |
21 |
Correct |
14 ms |
1492 KB |
Output is correct |
22 |
Correct |
18 ms |
1620 KB |
Output is correct |
23 |
Correct |
10 ms |
1276 KB |
Output is correct |
24 |
Correct |
29 ms |
2004 KB |
Output is correct |
25 |
Correct |
30 ms |
2080 KB |
Output is correct |
26 |
Correct |
33 ms |
2196 KB |
Output is correct |
27 |
Correct |
33 ms |
2132 KB |
Output is correct |
28 |
Correct |
35 ms |
2132 KB |
Output is correct |
29 |
Correct |
38 ms |
2176 KB |
Output is correct |
30 |
Correct |
33 ms |
2132 KB |
Output is correct |
31 |
Correct |
33 ms |
2192 KB |
Output is correct |
32 |
Correct |
31 ms |
2132 KB |
Output is correct |
33 |
Correct |
32 ms |
2132 KB |
Output is correct |
34 |
Correct |
33 ms |
2132 KB |
Output is correct |
35 |
Correct |
36 ms |
2132 KB |
Output is correct |
36 |
Correct |
40 ms |
2184 KB |
Output is correct |
37 |
Correct |
139 ms |
4172 KB |
Output is correct |
38 |
Correct |
132 ms |
4156 KB |
Output is correct |
39 |
Correct |
224 ms |
4912 KB |
Output is correct |
40 |
Correct |
249 ms |
5424 KB |
Output is correct |
41 |
Correct |
299 ms |
5328 KB |
Output is correct |
42 |
Correct |
216 ms |
5068 KB |
Output is correct |
43 |
Correct |
208 ms |
5232 KB |
Output is correct |
44 |
Correct |
217 ms |
5304 KB |
Output is correct |
45 |
Correct |
225 ms |
5344 KB |
Output is correct |
46 |
Correct |
279 ms |
5452 KB |
Output is correct |
47 |
Correct |
207 ms |
5084 KB |
Output is correct |
48 |
Correct |
226 ms |
5212 KB |
Output is correct |
49 |
Correct |
221 ms |
4968 KB |
Output is correct |
50 |
Correct |
213 ms |
5080 KB |
Output is correct |
51 |
Correct |
208 ms |
4956 KB |
Output is correct |
52 |
Correct |
310 ms |
5712 KB |
Output is correct |
53 |
Incorrect |
206 ms |
5144 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |