#ifdef ONPC
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) {in >> p.first >> p.second; return in;}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2>& p) {out << p.first << ' ' << p.second; return out;}
template<typename T> istream& operator>>(istream& in, vector<T>& v) {for (auto& x : v) in >> x; return in;}
template<typename T> ostream& operator<<(ostream& out, vector<T>& v) {for (auto& x : v) out << x << ' '; return out;}
const int MAX_INT = 2147483647;
const int mod = 1e9 + 7;
const int MAXN = 250001;
int s = 0;
int n;
int ans[MAXN] = {};
vector<int> a;
vector<int> in[1 << 13];
void add(int lq, int rq, int id, int x, int l, int r) {
if (rq <= l || r <= lq) return;
if (lq <= l && r <= rq) {
in[x].push_back(id);
return;
}
int m = (l + r) / 2;
add(lq, rq, id, 2 * x + 1, l, m);
add(lq, rq, id, 2 * x + 2, m, r);
}
void calc(int x, int l, int r, bitset<MAXN>& b) {
bitset<MAXN> nb = b;
for (auto id : in[x]) b |= (b << a[id]);
if (l + 1 == r) {
if (l == n - 1) {
if (s % 2 == 1 || !b[s / 2]) {
fill(ans, ans + MAXN, 0);
}
}
if (l >= n && (l - n) % 2 == 0) {
int cur = (l - n) / 2;
for (int i = 1; i < MAXN; i++) {
if ((s - a[cur] + i) % 2 == 1 || !b[(s - a[cur] + i) / 2]) {
ans[i] = 0;
}
}
}
} else {
int m = (l + r) / 2;
calc(2 * x + 1, l, m, b);
calc(2 * x + 2, m, r, b);
}
swap(nb, b);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
for (int i = 0; i < n; i++) {
add(0, n + 2 * i, i, 0, 0, 3 * n);
add(n + 2 * i + 1, 3 * n, i, 0, 0, 3 * n);
}
fill(ans + 1, ans + MAXN, 1);
bitset<MAXN> b;
b[0] = 1;
calc(0, 0, 3 * n, b);
vector<int> good;
for (int i = 1; i < MAXN; i++) {
if (ans[i]) {
good.push_back(i);
}
}
cout << good.size() << '\n';
cout << good << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1884 KB |
Output is correct |
5 |
Correct |
6 ms |
2140 KB |
Output is correct |
6 |
Correct |
5 ms |
2140 KB |
Output is correct |
7 |
Correct |
4 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1884 KB |
Output is correct |
5 |
Correct |
6 ms |
2140 KB |
Output is correct |
6 |
Correct |
5 ms |
2140 KB |
Output is correct |
7 |
Correct |
4 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
14 ms |
2392 KB |
Output is correct |
11 |
Correct |
13 ms |
2396 KB |
Output is correct |
12 |
Correct |
13 ms |
2396 KB |
Output is correct |
13 |
Correct |
12 ms |
2136 KB |
Output is correct |
14 |
Correct |
12 ms |
2140 KB |
Output is correct |
15 |
Correct |
12 ms |
2396 KB |
Output is correct |
16 |
Correct |
13 ms |
2140 KB |
Output is correct |
17 |
Correct |
9 ms |
2292 KB |
Output is correct |
18 |
Correct |
11 ms |
2396 KB |
Output is correct |
19 |
Correct |
15 ms |
2392 KB |
Output is correct |
20 |
Correct |
13 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1884 KB |
Output is correct |
5 |
Correct |
6 ms |
2140 KB |
Output is correct |
6 |
Correct |
5 ms |
2140 KB |
Output is correct |
7 |
Correct |
4 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
14 ms |
2392 KB |
Output is correct |
11 |
Correct |
13 ms |
2396 KB |
Output is correct |
12 |
Correct |
13 ms |
2396 KB |
Output is correct |
13 |
Correct |
12 ms |
2136 KB |
Output is correct |
14 |
Correct |
12 ms |
2140 KB |
Output is correct |
15 |
Correct |
12 ms |
2396 KB |
Output is correct |
16 |
Correct |
13 ms |
2140 KB |
Output is correct |
17 |
Correct |
9 ms |
2292 KB |
Output is correct |
18 |
Correct |
11 ms |
2396 KB |
Output is correct |
19 |
Correct |
15 ms |
2392 KB |
Output is correct |
20 |
Correct |
13 ms |
2396 KB |
Output is correct |
21 |
Correct |
26 ms |
2396 KB |
Output is correct |
22 |
Correct |
31 ms |
2484 KB |
Output is correct |
23 |
Correct |
21 ms |
2488 KB |
Output is correct |
24 |
Correct |
39 ms |
2560 KB |
Output is correct |
25 |
Correct |
39 ms |
2580 KB |
Output is correct |
26 |
Correct |
44 ms |
2396 KB |
Output is correct |
27 |
Correct |
44 ms |
2576 KB |
Output is correct |
28 |
Correct |
41 ms |
2396 KB |
Output is correct |
29 |
Correct |
41 ms |
2396 KB |
Output is correct |
30 |
Correct |
44 ms |
2396 KB |
Output is correct |
31 |
Correct |
43 ms |
2392 KB |
Output is correct |
32 |
Correct |
41 ms |
2472 KB |
Output is correct |
33 |
Correct |
48 ms |
2396 KB |
Output is correct |
34 |
Correct |
41 ms |
2396 KB |
Output is correct |
35 |
Correct |
41 ms |
2648 KB |
Output is correct |
36 |
Correct |
41 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1884 KB |
Output is correct |
5 |
Correct |
6 ms |
2140 KB |
Output is correct |
6 |
Correct |
5 ms |
2140 KB |
Output is correct |
7 |
Correct |
4 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
14 ms |
2392 KB |
Output is correct |
11 |
Correct |
13 ms |
2396 KB |
Output is correct |
12 |
Correct |
13 ms |
2396 KB |
Output is correct |
13 |
Correct |
12 ms |
2136 KB |
Output is correct |
14 |
Correct |
12 ms |
2140 KB |
Output is correct |
15 |
Correct |
12 ms |
2396 KB |
Output is correct |
16 |
Correct |
13 ms |
2140 KB |
Output is correct |
17 |
Correct |
9 ms |
2292 KB |
Output is correct |
18 |
Correct |
11 ms |
2396 KB |
Output is correct |
19 |
Correct |
15 ms |
2392 KB |
Output is correct |
20 |
Correct |
13 ms |
2396 KB |
Output is correct |
21 |
Correct |
26 ms |
2396 KB |
Output is correct |
22 |
Correct |
31 ms |
2484 KB |
Output is correct |
23 |
Correct |
21 ms |
2488 KB |
Output is correct |
24 |
Correct |
39 ms |
2560 KB |
Output is correct |
25 |
Correct |
39 ms |
2580 KB |
Output is correct |
26 |
Correct |
44 ms |
2396 KB |
Output is correct |
27 |
Correct |
44 ms |
2576 KB |
Output is correct |
28 |
Correct |
41 ms |
2396 KB |
Output is correct |
29 |
Correct |
41 ms |
2396 KB |
Output is correct |
30 |
Correct |
44 ms |
2396 KB |
Output is correct |
31 |
Correct |
43 ms |
2392 KB |
Output is correct |
32 |
Correct |
41 ms |
2472 KB |
Output is correct |
33 |
Correct |
48 ms |
2396 KB |
Output is correct |
34 |
Correct |
41 ms |
2396 KB |
Output is correct |
35 |
Correct |
41 ms |
2648 KB |
Output is correct |
36 |
Correct |
41 ms |
2392 KB |
Output is correct |
37 |
Correct |
84 ms |
2664 KB |
Output is correct |
38 |
Correct |
82 ms |
2668 KB |
Output is correct |
39 |
Correct |
101 ms |
2472 KB |
Output is correct |
40 |
Correct |
115 ms |
2676 KB |
Output is correct |
41 |
Correct |
112 ms |
2652 KB |
Output is correct |
42 |
Correct |
104 ms |
2680 KB |
Output is correct |
43 |
Correct |
105 ms |
2900 KB |
Output is correct |
44 |
Correct |
114 ms |
2928 KB |
Output is correct |
45 |
Correct |
105 ms |
2932 KB |
Output is correct |
46 |
Correct |
110 ms |
2652 KB |
Output is correct |
47 |
Correct |
109 ms |
2676 KB |
Output is correct |
48 |
Correct |
104 ms |
2896 KB |
Output is correct |
49 |
Correct |
102 ms |
2676 KB |
Output is correct |
50 |
Correct |
109 ms |
2824 KB |
Output is correct |
51 |
Correct |
107 ms |
2652 KB |
Output is correct |
52 |
Correct |
115 ms |
2924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1884 KB |
Output is correct |
5 |
Correct |
6 ms |
2140 KB |
Output is correct |
6 |
Correct |
5 ms |
2140 KB |
Output is correct |
7 |
Correct |
4 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
14 ms |
2392 KB |
Output is correct |
11 |
Correct |
13 ms |
2396 KB |
Output is correct |
12 |
Correct |
13 ms |
2396 KB |
Output is correct |
13 |
Correct |
12 ms |
2136 KB |
Output is correct |
14 |
Correct |
12 ms |
2140 KB |
Output is correct |
15 |
Correct |
12 ms |
2396 KB |
Output is correct |
16 |
Correct |
13 ms |
2140 KB |
Output is correct |
17 |
Correct |
9 ms |
2292 KB |
Output is correct |
18 |
Correct |
11 ms |
2396 KB |
Output is correct |
19 |
Correct |
15 ms |
2392 KB |
Output is correct |
20 |
Correct |
13 ms |
2396 KB |
Output is correct |
21 |
Correct |
26 ms |
2396 KB |
Output is correct |
22 |
Correct |
31 ms |
2484 KB |
Output is correct |
23 |
Correct |
21 ms |
2488 KB |
Output is correct |
24 |
Correct |
39 ms |
2560 KB |
Output is correct |
25 |
Correct |
39 ms |
2580 KB |
Output is correct |
26 |
Correct |
44 ms |
2396 KB |
Output is correct |
27 |
Correct |
44 ms |
2576 KB |
Output is correct |
28 |
Correct |
41 ms |
2396 KB |
Output is correct |
29 |
Correct |
41 ms |
2396 KB |
Output is correct |
30 |
Correct |
44 ms |
2396 KB |
Output is correct |
31 |
Correct |
43 ms |
2392 KB |
Output is correct |
32 |
Correct |
41 ms |
2472 KB |
Output is correct |
33 |
Correct |
48 ms |
2396 KB |
Output is correct |
34 |
Correct |
41 ms |
2396 KB |
Output is correct |
35 |
Correct |
41 ms |
2648 KB |
Output is correct |
36 |
Correct |
41 ms |
2392 KB |
Output is correct |
37 |
Correct |
84 ms |
2664 KB |
Output is correct |
38 |
Correct |
82 ms |
2668 KB |
Output is correct |
39 |
Correct |
101 ms |
2472 KB |
Output is correct |
40 |
Correct |
115 ms |
2676 KB |
Output is correct |
41 |
Correct |
112 ms |
2652 KB |
Output is correct |
42 |
Correct |
104 ms |
2680 KB |
Output is correct |
43 |
Correct |
105 ms |
2900 KB |
Output is correct |
44 |
Correct |
114 ms |
2928 KB |
Output is correct |
45 |
Correct |
105 ms |
2932 KB |
Output is correct |
46 |
Correct |
110 ms |
2652 KB |
Output is correct |
47 |
Correct |
109 ms |
2676 KB |
Output is correct |
48 |
Correct |
104 ms |
2896 KB |
Output is correct |
49 |
Correct |
102 ms |
2676 KB |
Output is correct |
50 |
Correct |
109 ms |
2824 KB |
Output is correct |
51 |
Correct |
107 ms |
2652 KB |
Output is correct |
52 |
Correct |
115 ms |
2924 KB |
Output is correct |
53 |
Correct |
136 ms |
3032 KB |
Output is correct |
54 |
Correct |
153 ms |
3032 KB |
Output is correct |
55 |
Correct |
154 ms |
3160 KB |
Output is correct |
56 |
Correct |
127 ms |
2900 KB |
Output is correct |
57 |
Correct |
152 ms |
3436 KB |
Output is correct |
58 |
Correct |
147 ms |
3036 KB |
Output is correct |
59 |
Correct |
156 ms |
3172 KB |
Output is correct |
60 |
Correct |
147 ms |
2784 KB |
Output is correct |
61 |
Correct |
148 ms |
3164 KB |
Output is correct |
62 |
Correct |
160 ms |
3056 KB |
Output is correct |
63 |
Correct |
135 ms |
3276 KB |
Output is correct |
64 |
Correct |
133 ms |
3060 KB |
Output is correct |
65 |
Correct |
131 ms |
2680 KB |
Output is correct |
66 |
Correct |
127 ms |
2948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1884 KB |
Output is correct |
5 |
Correct |
6 ms |
2140 KB |
Output is correct |
6 |
Correct |
5 ms |
2140 KB |
Output is correct |
7 |
Correct |
4 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
14 ms |
2392 KB |
Output is correct |
11 |
Correct |
13 ms |
2396 KB |
Output is correct |
12 |
Correct |
13 ms |
2396 KB |
Output is correct |
13 |
Correct |
12 ms |
2136 KB |
Output is correct |
14 |
Correct |
12 ms |
2140 KB |
Output is correct |
15 |
Correct |
12 ms |
2396 KB |
Output is correct |
16 |
Correct |
13 ms |
2140 KB |
Output is correct |
17 |
Correct |
9 ms |
2292 KB |
Output is correct |
18 |
Correct |
11 ms |
2396 KB |
Output is correct |
19 |
Correct |
15 ms |
2392 KB |
Output is correct |
20 |
Correct |
13 ms |
2396 KB |
Output is correct |
21 |
Correct |
26 ms |
2396 KB |
Output is correct |
22 |
Correct |
31 ms |
2484 KB |
Output is correct |
23 |
Correct |
21 ms |
2488 KB |
Output is correct |
24 |
Correct |
39 ms |
2560 KB |
Output is correct |
25 |
Correct |
39 ms |
2580 KB |
Output is correct |
26 |
Correct |
44 ms |
2396 KB |
Output is correct |
27 |
Correct |
44 ms |
2576 KB |
Output is correct |
28 |
Correct |
41 ms |
2396 KB |
Output is correct |
29 |
Correct |
41 ms |
2396 KB |
Output is correct |
30 |
Correct |
44 ms |
2396 KB |
Output is correct |
31 |
Correct |
43 ms |
2392 KB |
Output is correct |
32 |
Correct |
41 ms |
2472 KB |
Output is correct |
33 |
Correct |
48 ms |
2396 KB |
Output is correct |
34 |
Correct |
41 ms |
2396 KB |
Output is correct |
35 |
Correct |
41 ms |
2648 KB |
Output is correct |
36 |
Correct |
41 ms |
2392 KB |
Output is correct |
37 |
Correct |
84 ms |
2664 KB |
Output is correct |
38 |
Correct |
82 ms |
2668 KB |
Output is correct |
39 |
Correct |
101 ms |
2472 KB |
Output is correct |
40 |
Correct |
115 ms |
2676 KB |
Output is correct |
41 |
Correct |
112 ms |
2652 KB |
Output is correct |
42 |
Correct |
104 ms |
2680 KB |
Output is correct |
43 |
Correct |
105 ms |
2900 KB |
Output is correct |
44 |
Correct |
114 ms |
2928 KB |
Output is correct |
45 |
Correct |
105 ms |
2932 KB |
Output is correct |
46 |
Correct |
110 ms |
2652 KB |
Output is correct |
47 |
Correct |
109 ms |
2676 KB |
Output is correct |
48 |
Correct |
104 ms |
2896 KB |
Output is correct |
49 |
Correct |
102 ms |
2676 KB |
Output is correct |
50 |
Correct |
109 ms |
2824 KB |
Output is correct |
51 |
Correct |
107 ms |
2652 KB |
Output is correct |
52 |
Correct |
115 ms |
2924 KB |
Output is correct |
53 |
Correct |
136 ms |
3032 KB |
Output is correct |
54 |
Correct |
153 ms |
3032 KB |
Output is correct |
55 |
Correct |
154 ms |
3160 KB |
Output is correct |
56 |
Correct |
127 ms |
2900 KB |
Output is correct |
57 |
Correct |
152 ms |
3436 KB |
Output is correct |
58 |
Correct |
147 ms |
3036 KB |
Output is correct |
59 |
Correct |
156 ms |
3172 KB |
Output is correct |
60 |
Correct |
147 ms |
2784 KB |
Output is correct |
61 |
Correct |
148 ms |
3164 KB |
Output is correct |
62 |
Correct |
160 ms |
3056 KB |
Output is correct |
63 |
Correct |
135 ms |
3276 KB |
Output is correct |
64 |
Correct |
133 ms |
3060 KB |
Output is correct |
65 |
Correct |
131 ms |
2680 KB |
Output is correct |
66 |
Correct |
127 ms |
2948 KB |
Output is correct |
67 |
Correct |
185 ms |
3168 KB |
Output is correct |
68 |
Correct |
208 ms |
2800 KB |
Output is correct |
69 |
Correct |
218 ms |
3944 KB |
Output is correct |
70 |
Correct |
233 ms |
3428 KB |
Output is correct |
71 |
Correct |
219 ms |
3564 KB |
Output is correct |
72 |
Correct |
212 ms |
2800 KB |
Output is correct |
73 |
Correct |
217 ms |
2796 KB |
Output is correct |
74 |
Correct |
219 ms |
3948 KB |
Output is correct |
75 |
Correct |
217 ms |
3688 KB |
Output is correct |
76 |
Correct |
224 ms |
3936 KB |
Output is correct |
77 |
Correct |
261 ms |
3944 KB |
Output is correct |