#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 5;
const int S = N * N;
int cur [S];
int nxt [S];
int without [S];
bitset<S> ans;
bitset<S> Get;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a (n);
for (int i = 0; i < n; i++) cin >> a[i];
int whole_sum = accumulate (a.begin(), a.end(), 0);
cur[0] = nxt[0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < S; j++) {
nxt[j] = cur[j];
if (j - a[i] >= 0) nxt[j] += cur[j - a[i]];
}
for (int j = 0; j < S; j++) {
cur[j] = nxt[j];
nxt[j] = 0;
}
nxt[0] = 1;
}
if ((whole_sum & 1) || (cur[whole_sum / 2] == 0) ) {
cout << 0 << '\n';
return 0;
}
/*
for (int i = 0; i <= 10; i++) {
cout << i << ' ' << cur[i] << '\n';
}
cout << '\n';
*/
ans.set();
for (int i = 0; i < n; i++) {
whole_sum -= a[i];
for (int j = 0; j < S; j++) {
without[j] = cur[j];
}
// Remover o efeito da moeda i
for (int j = a[i]; j < S; j++) {
if (without[j]) without[j] -= without[j - a[i]];
}
Get.reset();
for (int j = 0; j <= whole_sum; j++) {
if (without[j]) {
int left = j;
int right = whole_sum - j;
Get[abs(left - right)] = 1;
}
}
ans &= Get;
whole_sum += a[i];
}
cout << ans.count() << '\n';
for (int i = 0; i < S; i++) if (ans[i]) cout << i << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3456 KB |
Output is correct |
2 |
Correct |
15 ms |
3456 KB |
Output is correct |
3 |
Correct |
9 ms |
2304 KB |
Output is correct |
4 |
Correct |
12 ms |
3456 KB |
Output is correct |
5 |
Correct |
15 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
11 ms |
3456 KB |
Output is correct |
8 |
Correct |
19 ms |
3456 KB |
Output is correct |
9 |
Correct |
14 ms |
3328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3456 KB |
Output is correct |
2 |
Correct |
15 ms |
3456 KB |
Output is correct |
3 |
Correct |
9 ms |
2304 KB |
Output is correct |
4 |
Correct |
12 ms |
3456 KB |
Output is correct |
5 |
Correct |
15 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
11 ms |
3456 KB |
Output is correct |
8 |
Correct |
19 ms |
3456 KB |
Output is correct |
9 |
Correct |
14 ms |
3328 KB |
Output is correct |
10 |
Correct |
30 ms |
3328 KB |
Output is correct |
11 |
Correct |
30 ms |
3328 KB |
Output is correct |
12 |
Correct |
51 ms |
3404 KB |
Output is correct |
13 |
Correct |
26 ms |
3328 KB |
Output is correct |
14 |
Correct |
28 ms |
3328 KB |
Output is correct |
15 |
Correct |
49 ms |
3320 KB |
Output is correct |
16 |
Correct |
30 ms |
3328 KB |
Output is correct |
17 |
Correct |
21 ms |
3328 KB |
Output is correct |
18 |
Correct |
26 ms |
3328 KB |
Output is correct |
19 |
Correct |
26 ms |
3328 KB |
Output is correct |
20 |
Correct |
29 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3456 KB |
Output is correct |
2 |
Correct |
15 ms |
3456 KB |
Output is correct |
3 |
Correct |
9 ms |
2304 KB |
Output is correct |
4 |
Correct |
12 ms |
3456 KB |
Output is correct |
5 |
Correct |
15 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
11 ms |
3456 KB |
Output is correct |
8 |
Correct |
19 ms |
3456 KB |
Output is correct |
9 |
Correct |
14 ms |
3328 KB |
Output is correct |
10 |
Correct |
30 ms |
3328 KB |
Output is correct |
11 |
Correct |
30 ms |
3328 KB |
Output is correct |
12 |
Correct |
51 ms |
3404 KB |
Output is correct |
13 |
Correct |
26 ms |
3328 KB |
Output is correct |
14 |
Correct |
28 ms |
3328 KB |
Output is correct |
15 |
Correct |
49 ms |
3320 KB |
Output is correct |
16 |
Correct |
30 ms |
3328 KB |
Output is correct |
17 |
Correct |
21 ms |
3328 KB |
Output is correct |
18 |
Correct |
26 ms |
3328 KB |
Output is correct |
19 |
Correct |
26 ms |
3328 KB |
Output is correct |
20 |
Correct |
29 ms |
3456 KB |
Output is correct |
21 |
Correct |
57 ms |
3448 KB |
Output is correct |
22 |
Correct |
64 ms |
3324 KB |
Output is correct |
23 |
Correct |
46 ms |
3328 KB |
Output is correct |
24 |
Correct |
82 ms |
3448 KB |
Output is correct |
25 |
Correct |
79 ms |
3448 KB |
Output is correct |
26 |
Correct |
84 ms |
3448 KB |
Output is correct |
27 |
Correct |
94 ms |
3400 KB |
Output is correct |
28 |
Correct |
84 ms |
3320 KB |
Output is correct |
29 |
Correct |
89 ms |
3320 KB |
Output is correct |
30 |
Correct |
89 ms |
3320 KB |
Output is correct |
31 |
Correct |
84 ms |
3448 KB |
Output is correct |
32 |
Correct |
85 ms |
3448 KB |
Output is correct |
33 |
Correct |
83 ms |
3440 KB |
Output is correct |
34 |
Correct |
84 ms |
3320 KB |
Output is correct |
35 |
Correct |
87 ms |
3404 KB |
Output is correct |
36 |
Correct |
97 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3456 KB |
Output is correct |
2 |
Correct |
15 ms |
3456 KB |
Output is correct |
3 |
Correct |
9 ms |
2304 KB |
Output is correct |
4 |
Correct |
12 ms |
3456 KB |
Output is correct |
5 |
Correct |
15 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
11 ms |
3456 KB |
Output is correct |
8 |
Correct |
19 ms |
3456 KB |
Output is correct |
9 |
Correct |
14 ms |
3328 KB |
Output is correct |
10 |
Correct |
30 ms |
3328 KB |
Output is correct |
11 |
Correct |
30 ms |
3328 KB |
Output is correct |
12 |
Correct |
51 ms |
3404 KB |
Output is correct |
13 |
Correct |
26 ms |
3328 KB |
Output is correct |
14 |
Correct |
28 ms |
3328 KB |
Output is correct |
15 |
Correct |
49 ms |
3320 KB |
Output is correct |
16 |
Correct |
30 ms |
3328 KB |
Output is correct |
17 |
Correct |
21 ms |
3328 KB |
Output is correct |
18 |
Correct |
26 ms |
3328 KB |
Output is correct |
19 |
Correct |
26 ms |
3328 KB |
Output is correct |
20 |
Correct |
29 ms |
3456 KB |
Output is correct |
21 |
Correct |
57 ms |
3448 KB |
Output is correct |
22 |
Correct |
64 ms |
3324 KB |
Output is correct |
23 |
Correct |
46 ms |
3328 KB |
Output is correct |
24 |
Correct |
82 ms |
3448 KB |
Output is correct |
25 |
Correct |
79 ms |
3448 KB |
Output is correct |
26 |
Correct |
84 ms |
3448 KB |
Output is correct |
27 |
Correct |
94 ms |
3400 KB |
Output is correct |
28 |
Correct |
84 ms |
3320 KB |
Output is correct |
29 |
Correct |
89 ms |
3320 KB |
Output is correct |
30 |
Correct |
89 ms |
3320 KB |
Output is correct |
31 |
Correct |
84 ms |
3448 KB |
Output is correct |
32 |
Correct |
85 ms |
3448 KB |
Output is correct |
33 |
Correct |
83 ms |
3440 KB |
Output is correct |
34 |
Correct |
84 ms |
3320 KB |
Output is correct |
35 |
Correct |
87 ms |
3404 KB |
Output is correct |
36 |
Correct |
97 ms |
3576 KB |
Output is correct |
37 |
Correct |
169 ms |
3448 KB |
Output is correct |
38 |
Correct |
166 ms |
3448 KB |
Output is correct |
39 |
Correct |
208 ms |
3448 KB |
Output is correct |
40 |
Correct |
236 ms |
3448 KB |
Output is correct |
41 |
Correct |
232 ms |
3320 KB |
Output is correct |
42 |
Correct |
213 ms |
3448 KB |
Output is correct |
43 |
Correct |
218 ms |
3704 KB |
Output is correct |
44 |
Correct |
226 ms |
3576 KB |
Output is correct |
45 |
Correct |
234 ms |
3468 KB |
Output is correct |
46 |
Correct |
227 ms |
3448 KB |
Output is correct |
47 |
Correct |
220 ms |
3448 KB |
Output is correct |
48 |
Correct |
238 ms |
3448 KB |
Output is correct |
49 |
Correct |
221 ms |
3448 KB |
Output is correct |
50 |
Correct |
217 ms |
3576 KB |
Output is correct |
51 |
Correct |
120 ms |
2304 KB |
Output is correct |
52 |
Correct |
259 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3456 KB |
Output is correct |
2 |
Correct |
15 ms |
3456 KB |
Output is correct |
3 |
Correct |
9 ms |
2304 KB |
Output is correct |
4 |
Correct |
12 ms |
3456 KB |
Output is correct |
5 |
Correct |
15 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
11 ms |
3456 KB |
Output is correct |
8 |
Correct |
19 ms |
3456 KB |
Output is correct |
9 |
Correct |
14 ms |
3328 KB |
Output is correct |
10 |
Correct |
30 ms |
3328 KB |
Output is correct |
11 |
Correct |
30 ms |
3328 KB |
Output is correct |
12 |
Correct |
51 ms |
3404 KB |
Output is correct |
13 |
Correct |
26 ms |
3328 KB |
Output is correct |
14 |
Correct |
28 ms |
3328 KB |
Output is correct |
15 |
Correct |
49 ms |
3320 KB |
Output is correct |
16 |
Correct |
30 ms |
3328 KB |
Output is correct |
17 |
Correct |
21 ms |
3328 KB |
Output is correct |
18 |
Correct |
26 ms |
3328 KB |
Output is correct |
19 |
Correct |
26 ms |
3328 KB |
Output is correct |
20 |
Correct |
29 ms |
3456 KB |
Output is correct |
21 |
Correct |
57 ms |
3448 KB |
Output is correct |
22 |
Correct |
64 ms |
3324 KB |
Output is correct |
23 |
Correct |
46 ms |
3328 KB |
Output is correct |
24 |
Correct |
82 ms |
3448 KB |
Output is correct |
25 |
Correct |
79 ms |
3448 KB |
Output is correct |
26 |
Correct |
84 ms |
3448 KB |
Output is correct |
27 |
Correct |
94 ms |
3400 KB |
Output is correct |
28 |
Correct |
84 ms |
3320 KB |
Output is correct |
29 |
Correct |
89 ms |
3320 KB |
Output is correct |
30 |
Correct |
89 ms |
3320 KB |
Output is correct |
31 |
Correct |
84 ms |
3448 KB |
Output is correct |
32 |
Correct |
85 ms |
3448 KB |
Output is correct |
33 |
Correct |
83 ms |
3440 KB |
Output is correct |
34 |
Correct |
84 ms |
3320 KB |
Output is correct |
35 |
Correct |
87 ms |
3404 KB |
Output is correct |
36 |
Correct |
97 ms |
3576 KB |
Output is correct |
37 |
Correct |
169 ms |
3448 KB |
Output is correct |
38 |
Correct |
166 ms |
3448 KB |
Output is correct |
39 |
Correct |
208 ms |
3448 KB |
Output is correct |
40 |
Correct |
236 ms |
3448 KB |
Output is correct |
41 |
Correct |
232 ms |
3320 KB |
Output is correct |
42 |
Correct |
213 ms |
3448 KB |
Output is correct |
43 |
Correct |
218 ms |
3704 KB |
Output is correct |
44 |
Correct |
226 ms |
3576 KB |
Output is correct |
45 |
Correct |
234 ms |
3468 KB |
Output is correct |
46 |
Correct |
227 ms |
3448 KB |
Output is correct |
47 |
Correct |
220 ms |
3448 KB |
Output is correct |
48 |
Correct |
238 ms |
3448 KB |
Output is correct |
49 |
Correct |
221 ms |
3448 KB |
Output is correct |
50 |
Correct |
217 ms |
3576 KB |
Output is correct |
51 |
Correct |
120 ms |
2304 KB |
Output is correct |
52 |
Correct |
259 ms |
3576 KB |
Output is correct |
53 |
Correct |
271 ms |
3552 KB |
Output is correct |
54 |
Correct |
318 ms |
3576 KB |
Output is correct |
55 |
Correct |
348 ms |
3704 KB |
Output is correct |
56 |
Correct |
286 ms |
3660 KB |
Output is correct |
57 |
Correct |
358 ms |
3704 KB |
Output is correct |
58 |
Correct |
334 ms |
3576 KB |
Output is correct |
59 |
Correct |
334 ms |
3576 KB |
Output is correct |
60 |
Correct |
169 ms |
2304 KB |
Output is correct |
61 |
Correct |
347 ms |
3704 KB |
Output is correct |
62 |
Correct |
315 ms |
3832 KB |
Output is correct |
63 |
Correct |
321 ms |
3704 KB |
Output is correct |
64 |
Correct |
324 ms |
3704 KB |
Output is correct |
65 |
Correct |
277 ms |
3324 KB |
Output is correct |
66 |
Correct |
262 ms |
3448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3456 KB |
Output is correct |
2 |
Correct |
15 ms |
3456 KB |
Output is correct |
3 |
Correct |
9 ms |
2304 KB |
Output is correct |
4 |
Correct |
12 ms |
3456 KB |
Output is correct |
5 |
Correct |
15 ms |
3328 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
11 ms |
3456 KB |
Output is correct |
8 |
Correct |
19 ms |
3456 KB |
Output is correct |
9 |
Correct |
14 ms |
3328 KB |
Output is correct |
10 |
Correct |
30 ms |
3328 KB |
Output is correct |
11 |
Correct |
30 ms |
3328 KB |
Output is correct |
12 |
Correct |
51 ms |
3404 KB |
Output is correct |
13 |
Correct |
26 ms |
3328 KB |
Output is correct |
14 |
Correct |
28 ms |
3328 KB |
Output is correct |
15 |
Correct |
49 ms |
3320 KB |
Output is correct |
16 |
Correct |
30 ms |
3328 KB |
Output is correct |
17 |
Correct |
21 ms |
3328 KB |
Output is correct |
18 |
Correct |
26 ms |
3328 KB |
Output is correct |
19 |
Correct |
26 ms |
3328 KB |
Output is correct |
20 |
Correct |
29 ms |
3456 KB |
Output is correct |
21 |
Correct |
57 ms |
3448 KB |
Output is correct |
22 |
Correct |
64 ms |
3324 KB |
Output is correct |
23 |
Correct |
46 ms |
3328 KB |
Output is correct |
24 |
Correct |
82 ms |
3448 KB |
Output is correct |
25 |
Correct |
79 ms |
3448 KB |
Output is correct |
26 |
Correct |
84 ms |
3448 KB |
Output is correct |
27 |
Correct |
94 ms |
3400 KB |
Output is correct |
28 |
Correct |
84 ms |
3320 KB |
Output is correct |
29 |
Correct |
89 ms |
3320 KB |
Output is correct |
30 |
Correct |
89 ms |
3320 KB |
Output is correct |
31 |
Correct |
84 ms |
3448 KB |
Output is correct |
32 |
Correct |
85 ms |
3448 KB |
Output is correct |
33 |
Correct |
83 ms |
3440 KB |
Output is correct |
34 |
Correct |
84 ms |
3320 KB |
Output is correct |
35 |
Correct |
87 ms |
3404 KB |
Output is correct |
36 |
Correct |
97 ms |
3576 KB |
Output is correct |
37 |
Correct |
169 ms |
3448 KB |
Output is correct |
38 |
Correct |
166 ms |
3448 KB |
Output is correct |
39 |
Correct |
208 ms |
3448 KB |
Output is correct |
40 |
Correct |
236 ms |
3448 KB |
Output is correct |
41 |
Correct |
232 ms |
3320 KB |
Output is correct |
42 |
Correct |
213 ms |
3448 KB |
Output is correct |
43 |
Correct |
218 ms |
3704 KB |
Output is correct |
44 |
Correct |
226 ms |
3576 KB |
Output is correct |
45 |
Correct |
234 ms |
3468 KB |
Output is correct |
46 |
Correct |
227 ms |
3448 KB |
Output is correct |
47 |
Correct |
220 ms |
3448 KB |
Output is correct |
48 |
Correct |
238 ms |
3448 KB |
Output is correct |
49 |
Correct |
221 ms |
3448 KB |
Output is correct |
50 |
Correct |
217 ms |
3576 KB |
Output is correct |
51 |
Correct |
120 ms |
2304 KB |
Output is correct |
52 |
Correct |
259 ms |
3576 KB |
Output is correct |
53 |
Correct |
271 ms |
3552 KB |
Output is correct |
54 |
Correct |
318 ms |
3576 KB |
Output is correct |
55 |
Correct |
348 ms |
3704 KB |
Output is correct |
56 |
Correct |
286 ms |
3660 KB |
Output is correct |
57 |
Correct |
358 ms |
3704 KB |
Output is correct |
58 |
Correct |
334 ms |
3576 KB |
Output is correct |
59 |
Correct |
334 ms |
3576 KB |
Output is correct |
60 |
Correct |
169 ms |
2304 KB |
Output is correct |
61 |
Correct |
347 ms |
3704 KB |
Output is correct |
62 |
Correct |
315 ms |
3832 KB |
Output is correct |
63 |
Correct |
321 ms |
3704 KB |
Output is correct |
64 |
Correct |
324 ms |
3704 KB |
Output is correct |
65 |
Correct |
277 ms |
3324 KB |
Output is correct |
66 |
Correct |
262 ms |
3448 KB |
Output is correct |
67 |
Correct |
380 ms |
3704 KB |
Output is correct |
68 |
Correct |
236 ms |
2424 KB |
Output is correct |
69 |
Correct |
615 ms |
4088 KB |
Output is correct |
70 |
Correct |
528 ms |
3836 KB |
Output is correct |
71 |
Correct |
530 ms |
3832 KB |
Output is correct |
72 |
Correct |
520 ms |
3448 KB |
Output is correct |
73 |
Correct |
511 ms |
3320 KB |
Output is correct |
74 |
Correct |
631 ms |
4216 KB |
Output is correct |
75 |
Correct |
581 ms |
3960 KB |
Output is correct |
76 |
Correct |
625 ms |
4188 KB |
Output is correct |
77 |
Correct |
637 ms |
4088 KB |
Output is correct |