// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
const int nax = 505;
const int kax = nax * nax;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vector<int> A(N); for(auto& x : A) cin >> x;
bitset<kax> ans; ans.set();
function<void(int, int, bitset<kax>&)> dnc = [&](int l, int r, bitset<kax>& dp) {
// cout << l << " " << r << endl;
int m = (l + r) / 2;
if (l > r) return;
if (l == r) {
dp <<= A[l];
ans &= dp;
return;
}
bitset<kax> ndp;
// GO LEFT
ndp = dp;
for(int x = m + 1; x <= r; x++) ndp |= (ndp << 2*A[x]);
dnc(l, m, ndp);
// GO RIGHT
ndp = dp;
for(int x = l; x <= m; x++) ndp |= (ndp << 2*A[x]);
dnc(m+1, r, ndp);
};
int S = accumulate(begin(A), end(A), 0);
if (S % 2) {
cout << 0 << nl;
return 0;
}
bitset<kax> dp; dp[0] = 1;
for(auto x : A) dp |= (dp << x);
if (!dp[S / 2]) {
cout << 0 << nl;
return 0;
}
dp.reset(); dp[0] = 1;
dnc(0, N - 1, dp);
vector<int> ANS;
for(int SUM = 0; SUM <= S; SUM++) if (ans[SUM]) ANS.push_back(S - SUM);
reverse(begin(ANS), end(ANS));
cout << size(ANS) << nl;
for(auto x : ANS) cout << x << " ";
cout << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
824 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
824 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
952 KB |
Output is correct |
13 |
Correct |
2 ms |
948 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
956 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
2 ms |
908 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
824 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
952 KB |
Output is correct |
13 |
Correct |
2 ms |
948 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
956 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
2 ms |
908 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1212 KB |
Output is correct |
23 |
Correct |
4 ms |
1108 KB |
Output is correct |
24 |
Correct |
6 ms |
1192 KB |
Output is correct |
25 |
Correct |
6 ms |
1236 KB |
Output is correct |
26 |
Correct |
8 ms |
1208 KB |
Output is correct |
27 |
Correct |
6 ms |
1216 KB |
Output is correct |
28 |
Correct |
6 ms |
1192 KB |
Output is correct |
29 |
Correct |
6 ms |
1192 KB |
Output is correct |
30 |
Correct |
6 ms |
1108 KB |
Output is correct |
31 |
Correct |
6 ms |
1188 KB |
Output is correct |
32 |
Correct |
6 ms |
1208 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
9 ms |
1144 KB |
Output is correct |
35 |
Correct |
6 ms |
1080 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
824 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
952 KB |
Output is correct |
13 |
Correct |
2 ms |
948 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
956 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
2 ms |
908 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1212 KB |
Output is correct |
23 |
Correct |
4 ms |
1108 KB |
Output is correct |
24 |
Correct |
6 ms |
1192 KB |
Output is correct |
25 |
Correct |
6 ms |
1236 KB |
Output is correct |
26 |
Correct |
8 ms |
1208 KB |
Output is correct |
27 |
Correct |
6 ms |
1216 KB |
Output is correct |
28 |
Correct |
6 ms |
1192 KB |
Output is correct |
29 |
Correct |
6 ms |
1192 KB |
Output is correct |
30 |
Correct |
6 ms |
1108 KB |
Output is correct |
31 |
Correct |
6 ms |
1188 KB |
Output is correct |
32 |
Correct |
6 ms |
1208 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
9 ms |
1144 KB |
Output is correct |
35 |
Correct |
6 ms |
1080 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
17 ms |
1364 KB |
Output is correct |
38 |
Correct |
13 ms |
1364 KB |
Output is correct |
39 |
Correct |
16 ms |
1288 KB |
Output is correct |
40 |
Correct |
19 ms |
1496 KB |
Output is correct |
41 |
Correct |
18 ms |
1296 KB |
Output is correct |
42 |
Correct |
17 ms |
1464 KB |
Output is correct |
43 |
Correct |
17 ms |
1668 KB |
Output is correct |
44 |
Correct |
18 ms |
1620 KB |
Output is correct |
45 |
Correct |
18 ms |
1612 KB |
Output is correct |
46 |
Correct |
17 ms |
1364 KB |
Output is correct |
47 |
Correct |
18 ms |
1408 KB |
Output is correct |
48 |
Correct |
17 ms |
1492 KB |
Output is correct |
49 |
Correct |
16 ms |
1280 KB |
Output is correct |
50 |
Correct |
17 ms |
1416 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
21 ms |
1752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
824 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
952 KB |
Output is correct |
13 |
Correct |
2 ms |
948 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
956 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
2 ms |
908 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1212 KB |
Output is correct |
23 |
Correct |
4 ms |
1108 KB |
Output is correct |
24 |
Correct |
6 ms |
1192 KB |
Output is correct |
25 |
Correct |
6 ms |
1236 KB |
Output is correct |
26 |
Correct |
8 ms |
1208 KB |
Output is correct |
27 |
Correct |
6 ms |
1216 KB |
Output is correct |
28 |
Correct |
6 ms |
1192 KB |
Output is correct |
29 |
Correct |
6 ms |
1192 KB |
Output is correct |
30 |
Correct |
6 ms |
1108 KB |
Output is correct |
31 |
Correct |
6 ms |
1188 KB |
Output is correct |
32 |
Correct |
6 ms |
1208 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
9 ms |
1144 KB |
Output is correct |
35 |
Correct |
6 ms |
1080 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
17 ms |
1364 KB |
Output is correct |
38 |
Correct |
13 ms |
1364 KB |
Output is correct |
39 |
Correct |
16 ms |
1288 KB |
Output is correct |
40 |
Correct |
19 ms |
1496 KB |
Output is correct |
41 |
Correct |
18 ms |
1296 KB |
Output is correct |
42 |
Correct |
17 ms |
1464 KB |
Output is correct |
43 |
Correct |
17 ms |
1668 KB |
Output is correct |
44 |
Correct |
18 ms |
1620 KB |
Output is correct |
45 |
Correct |
18 ms |
1612 KB |
Output is correct |
46 |
Correct |
17 ms |
1364 KB |
Output is correct |
47 |
Correct |
18 ms |
1408 KB |
Output is correct |
48 |
Correct |
17 ms |
1492 KB |
Output is correct |
49 |
Correct |
16 ms |
1280 KB |
Output is correct |
50 |
Correct |
17 ms |
1416 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
21 ms |
1752 KB |
Output is correct |
53 |
Correct |
25 ms |
1620 KB |
Output is correct |
54 |
Correct |
26 ms |
1740 KB |
Output is correct |
55 |
Correct |
27 ms |
1868 KB |
Output is correct |
56 |
Correct |
28 ms |
1748 KB |
Output is correct |
57 |
Correct |
28 ms |
2008 KB |
Output is correct |
58 |
Correct |
26 ms |
1752 KB |
Output is correct |
59 |
Correct |
26 ms |
1760 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
26 ms |
1884 KB |
Output is correct |
62 |
Correct |
26 ms |
1872 KB |
Output is correct |
63 |
Correct |
24 ms |
1880 KB |
Output is correct |
64 |
Correct |
30 ms |
1888 KB |
Output is correct |
65 |
Correct |
25 ms |
1444 KB |
Output is correct |
66 |
Correct |
21 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
824 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
952 KB |
Output is correct |
13 |
Correct |
2 ms |
948 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
956 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
2 ms |
908 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1212 KB |
Output is correct |
23 |
Correct |
4 ms |
1108 KB |
Output is correct |
24 |
Correct |
6 ms |
1192 KB |
Output is correct |
25 |
Correct |
6 ms |
1236 KB |
Output is correct |
26 |
Correct |
8 ms |
1208 KB |
Output is correct |
27 |
Correct |
6 ms |
1216 KB |
Output is correct |
28 |
Correct |
6 ms |
1192 KB |
Output is correct |
29 |
Correct |
6 ms |
1192 KB |
Output is correct |
30 |
Correct |
6 ms |
1108 KB |
Output is correct |
31 |
Correct |
6 ms |
1188 KB |
Output is correct |
32 |
Correct |
6 ms |
1208 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
9 ms |
1144 KB |
Output is correct |
35 |
Correct |
6 ms |
1080 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
17 ms |
1364 KB |
Output is correct |
38 |
Correct |
13 ms |
1364 KB |
Output is correct |
39 |
Correct |
16 ms |
1288 KB |
Output is correct |
40 |
Correct |
19 ms |
1496 KB |
Output is correct |
41 |
Correct |
18 ms |
1296 KB |
Output is correct |
42 |
Correct |
17 ms |
1464 KB |
Output is correct |
43 |
Correct |
17 ms |
1668 KB |
Output is correct |
44 |
Correct |
18 ms |
1620 KB |
Output is correct |
45 |
Correct |
18 ms |
1612 KB |
Output is correct |
46 |
Correct |
17 ms |
1364 KB |
Output is correct |
47 |
Correct |
18 ms |
1408 KB |
Output is correct |
48 |
Correct |
17 ms |
1492 KB |
Output is correct |
49 |
Correct |
16 ms |
1280 KB |
Output is correct |
50 |
Correct |
17 ms |
1416 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
21 ms |
1752 KB |
Output is correct |
53 |
Correct |
25 ms |
1620 KB |
Output is correct |
54 |
Correct |
26 ms |
1740 KB |
Output is correct |
55 |
Correct |
27 ms |
1868 KB |
Output is correct |
56 |
Correct |
28 ms |
1748 KB |
Output is correct |
57 |
Correct |
28 ms |
2008 KB |
Output is correct |
58 |
Correct |
26 ms |
1752 KB |
Output is correct |
59 |
Correct |
26 ms |
1760 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
26 ms |
1884 KB |
Output is correct |
62 |
Correct |
26 ms |
1872 KB |
Output is correct |
63 |
Correct |
24 ms |
1880 KB |
Output is correct |
64 |
Correct |
30 ms |
1888 KB |
Output is correct |
65 |
Correct |
25 ms |
1444 KB |
Output is correct |
66 |
Correct |
21 ms |
1364 KB |
Output is correct |
67 |
Correct |
30 ms |
1880 KB |
Output is correct |
68 |
Correct |
4 ms |
340 KB |
Output is correct |
69 |
Correct |
40 ms |
2480 KB |
Output is correct |
70 |
Correct |
38 ms |
2140 KB |
Output is correct |
71 |
Correct |
38 ms |
2016 KB |
Output is correct |
72 |
Correct |
34 ms |
1364 KB |
Output is correct |
73 |
Correct |
35 ms |
1380 KB |
Output is correct |
74 |
Correct |
41 ms |
2520 KB |
Output is correct |
75 |
Correct |
40 ms |
2380 KB |
Output is correct |
76 |
Correct |
42 ms |
2488 KB |
Output is correct |
77 |
Correct |
41 ms |
2652 KB |
Output is correct |