#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wparentheses"
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define random random_device rd; mt19937 rng(rd())
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
i << '{' << j.size() << ':';
for (T ii : j) i << ' ' << ii;
return i << '}';
}
void Debug(bool _split) {}
template<typename T1, typename ...T2>
void Debug(bool _split, T1 x, T2 ...args) {
if (_split)
cerr << ", ";
cerr << x, Debug(true, args...);
}
template<typename T>
void Debuga(T *i, int n) {
cerr << '[';
for (int j = 0; j < n; ++j) cerr << i[j] << " ]"[j == n - 1];
cerr << endl;
}
#ifdef SYL
#define debug(args...) cerr << "\u001b[35mLine(" << __LINE__ << ") -> [" << #args << "] is [", Debug(false, args), cerr << "]\u001b[0m" << endl
#define debuga(i) cerr << "\u001b[35mLine(" << __LINE__ << ") -> [" << #i << "] is ", Debuga(i, sizeof(i) / sizeof(typeid(*i).name())), cerr << "\u001b[0m"
#else
#define debug(args...) void(0)
#define debuga(i) void(0)
#endif
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 0x3f3f3f3f, lg = 20;
const ll mod = 1e9 + 7, INF = 0x3f3f3f3f3f3f3f3f;
const int N = 500, C = N * (2 * N + 1), zro = N * N;
bitset<C> is[11][2];
bool ok[C];
int a[N];
void calc(int l, int r, int dep) {
is[dep + 1][0] = is[dep][0];
int nxt = 1, pre = 0;
while (l < r) {
is[dep + 1][nxt] = is[dep + 1][pre] << a[l];
is[dep + 1][nxt] |= is[dep + 1][pre] >> a[l];
swap(nxt, pre);
++l;
}
if (pre)
is[dep + 1][0] = is[dep + 1][1];
}
void dc(int l, int r, int dep) {
if (l == r - 1) {
for (int i = zro + 1; i < C; ++i)
ok[i] = ok[i] & is[dep][0].test(i);
return;
}
int m = l + r >> 1;
calc(l, m, dep);
dc(m, r, dep + 1);
calc(m, r, dep);
dc(l, m, dep + 1);
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
fill(ok, ok + C, true);
is[0][0].set(zro, true);
dc(0, n, 0);
calc(0, n, 0);
if (!is[1][0].test(zro))
return cout << 0, 0;
vector<int> ans;
for (int i = zro + 1; i < C; ++i)
if (ok[i])
ans.push_back(i - zro);
cout << ans.size() << '\n';
for (int i : ans)
cout << i << ' ';
}
/*
n^2C pre,suf
k * (n^2C + n/k * n/k * nC)
T(N) = 2 * (N/2 * maxN * C + T(N/2))
= 2T(N/2) + NmaxNC
n maxn c lgn
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1088 KB |
Output is correct |
2 |
Correct |
3 ms |
1212 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
6 ms |
1424 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
4 ms |
1216 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1088 KB |
Output is correct |
2 |
Correct |
3 ms |
1212 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
6 ms |
1424 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
4 ms |
1216 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
18 ms |
1548 KB |
Output is correct |
11 |
Correct |
13 ms |
1552 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
13 ms |
1548 KB |
Output is correct |
14 |
Correct |
12 ms |
1548 KB |
Output is correct |
15 |
Correct |
15 ms |
1548 KB |
Output is correct |
16 |
Correct |
14 ms |
1548 KB |
Output is correct |
17 |
Correct |
8 ms |
1472 KB |
Output is correct |
18 |
Correct |
14 ms |
1484 KB |
Output is correct |
19 |
Correct |
11 ms |
1548 KB |
Output is correct |
20 |
Correct |
12 ms |
1472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1088 KB |
Output is correct |
2 |
Correct |
3 ms |
1212 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
6 ms |
1424 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
4 ms |
1216 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
18 ms |
1548 KB |
Output is correct |
11 |
Correct |
13 ms |
1552 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
13 ms |
1548 KB |
Output is correct |
14 |
Correct |
12 ms |
1548 KB |
Output is correct |
15 |
Correct |
15 ms |
1548 KB |
Output is correct |
16 |
Correct |
14 ms |
1548 KB |
Output is correct |
17 |
Correct |
8 ms |
1472 KB |
Output is correct |
18 |
Correct |
14 ms |
1484 KB |
Output is correct |
19 |
Correct |
11 ms |
1548 KB |
Output is correct |
20 |
Correct |
12 ms |
1472 KB |
Output is correct |
21 |
Correct |
26 ms |
1664 KB |
Output is correct |
22 |
Correct |
30 ms |
1740 KB |
Output is correct |
23 |
Correct |
22 ms |
1652 KB |
Output is correct |
24 |
Correct |
44 ms |
1816 KB |
Output is correct |
25 |
Correct |
41 ms |
1784 KB |
Output is correct |
26 |
Correct |
42 ms |
1780 KB |
Output is correct |
27 |
Correct |
41 ms |
1740 KB |
Output is correct |
28 |
Correct |
45 ms |
1788 KB |
Output is correct |
29 |
Correct |
57 ms |
1788 KB |
Output is correct |
30 |
Correct |
41 ms |
1772 KB |
Output is correct |
31 |
Correct |
54 ms |
1772 KB |
Output is correct |
32 |
Correct |
44 ms |
1720 KB |
Output is correct |
33 |
Correct |
43 ms |
1740 KB |
Output is correct |
34 |
Correct |
54 ms |
1768 KB |
Output is correct |
35 |
Correct |
44 ms |
1776 KB |
Output is correct |
36 |
Correct |
59 ms |
1736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1088 KB |
Output is correct |
2 |
Correct |
3 ms |
1212 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
6 ms |
1424 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
4 ms |
1216 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
18 ms |
1548 KB |
Output is correct |
11 |
Correct |
13 ms |
1552 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
13 ms |
1548 KB |
Output is correct |
14 |
Correct |
12 ms |
1548 KB |
Output is correct |
15 |
Correct |
15 ms |
1548 KB |
Output is correct |
16 |
Correct |
14 ms |
1548 KB |
Output is correct |
17 |
Correct |
8 ms |
1472 KB |
Output is correct |
18 |
Correct |
14 ms |
1484 KB |
Output is correct |
19 |
Correct |
11 ms |
1548 KB |
Output is correct |
20 |
Correct |
12 ms |
1472 KB |
Output is correct |
21 |
Correct |
26 ms |
1664 KB |
Output is correct |
22 |
Correct |
30 ms |
1740 KB |
Output is correct |
23 |
Correct |
22 ms |
1652 KB |
Output is correct |
24 |
Correct |
44 ms |
1816 KB |
Output is correct |
25 |
Correct |
41 ms |
1784 KB |
Output is correct |
26 |
Correct |
42 ms |
1780 KB |
Output is correct |
27 |
Correct |
41 ms |
1740 KB |
Output is correct |
28 |
Correct |
45 ms |
1788 KB |
Output is correct |
29 |
Correct |
57 ms |
1788 KB |
Output is correct |
30 |
Correct |
41 ms |
1772 KB |
Output is correct |
31 |
Correct |
54 ms |
1772 KB |
Output is correct |
32 |
Correct |
44 ms |
1720 KB |
Output is correct |
33 |
Correct |
43 ms |
1740 KB |
Output is correct |
34 |
Correct |
54 ms |
1768 KB |
Output is correct |
35 |
Correct |
44 ms |
1776 KB |
Output is correct |
36 |
Correct |
59 ms |
1736 KB |
Output is correct |
37 |
Correct |
112 ms |
2028 KB |
Output is correct |
38 |
Correct |
97 ms |
2036 KB |
Output is correct |
39 |
Correct |
113 ms |
1976 KB |
Output is correct |
40 |
Correct |
128 ms |
2148 KB |
Output is correct |
41 |
Correct |
121 ms |
2020 KB |
Output is correct |
42 |
Correct |
112 ms |
2032 KB |
Output is correct |
43 |
Correct |
131 ms |
2280 KB |
Output is correct |
44 |
Correct |
112 ms |
2192 KB |
Output is correct |
45 |
Correct |
111 ms |
2236 KB |
Output is correct |
46 |
Correct |
134 ms |
1996 KB |
Output is correct |
47 |
Correct |
137 ms |
2024 KB |
Output is correct |
48 |
Correct |
113 ms |
2168 KB |
Output is correct |
49 |
Correct |
113 ms |
1900 KB |
Output is correct |
50 |
Correct |
121 ms |
2024 KB |
Output is correct |
51 |
Correct |
121 ms |
1900 KB |
Output is correct |
52 |
Correct |
121 ms |
2408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1088 KB |
Output is correct |
2 |
Correct |
3 ms |
1212 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
6 ms |
1424 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
4 ms |
1216 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
18 ms |
1548 KB |
Output is correct |
11 |
Correct |
13 ms |
1552 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
13 ms |
1548 KB |
Output is correct |
14 |
Correct |
12 ms |
1548 KB |
Output is correct |
15 |
Correct |
15 ms |
1548 KB |
Output is correct |
16 |
Correct |
14 ms |
1548 KB |
Output is correct |
17 |
Correct |
8 ms |
1472 KB |
Output is correct |
18 |
Correct |
14 ms |
1484 KB |
Output is correct |
19 |
Correct |
11 ms |
1548 KB |
Output is correct |
20 |
Correct |
12 ms |
1472 KB |
Output is correct |
21 |
Correct |
26 ms |
1664 KB |
Output is correct |
22 |
Correct |
30 ms |
1740 KB |
Output is correct |
23 |
Correct |
22 ms |
1652 KB |
Output is correct |
24 |
Correct |
44 ms |
1816 KB |
Output is correct |
25 |
Correct |
41 ms |
1784 KB |
Output is correct |
26 |
Correct |
42 ms |
1780 KB |
Output is correct |
27 |
Correct |
41 ms |
1740 KB |
Output is correct |
28 |
Correct |
45 ms |
1788 KB |
Output is correct |
29 |
Correct |
57 ms |
1788 KB |
Output is correct |
30 |
Correct |
41 ms |
1772 KB |
Output is correct |
31 |
Correct |
54 ms |
1772 KB |
Output is correct |
32 |
Correct |
44 ms |
1720 KB |
Output is correct |
33 |
Correct |
43 ms |
1740 KB |
Output is correct |
34 |
Correct |
54 ms |
1768 KB |
Output is correct |
35 |
Correct |
44 ms |
1776 KB |
Output is correct |
36 |
Correct |
59 ms |
1736 KB |
Output is correct |
37 |
Correct |
112 ms |
2028 KB |
Output is correct |
38 |
Correct |
97 ms |
2036 KB |
Output is correct |
39 |
Correct |
113 ms |
1976 KB |
Output is correct |
40 |
Correct |
128 ms |
2148 KB |
Output is correct |
41 |
Correct |
121 ms |
2020 KB |
Output is correct |
42 |
Correct |
112 ms |
2032 KB |
Output is correct |
43 |
Correct |
131 ms |
2280 KB |
Output is correct |
44 |
Correct |
112 ms |
2192 KB |
Output is correct |
45 |
Correct |
111 ms |
2236 KB |
Output is correct |
46 |
Correct |
134 ms |
1996 KB |
Output is correct |
47 |
Correct |
137 ms |
2024 KB |
Output is correct |
48 |
Correct |
113 ms |
2168 KB |
Output is correct |
49 |
Correct |
113 ms |
1900 KB |
Output is correct |
50 |
Correct |
121 ms |
2024 KB |
Output is correct |
51 |
Correct |
121 ms |
1900 KB |
Output is correct |
52 |
Correct |
121 ms |
2408 KB |
Output is correct |
53 |
Correct |
140 ms |
2276 KB |
Output is correct |
54 |
Correct |
172 ms |
2400 KB |
Output is correct |
55 |
Correct |
171 ms |
2536 KB |
Output is correct |
56 |
Correct |
140 ms |
2400 KB |
Output is correct |
57 |
Correct |
161 ms |
2664 KB |
Output is correct |
58 |
Correct |
196 ms |
2404 KB |
Output is correct |
59 |
Correct |
170 ms |
2536 KB |
Output is correct |
60 |
Correct |
159 ms |
2020 KB |
Output is correct |
61 |
Correct |
181 ms |
2532 KB |
Output is correct |
62 |
Correct |
156 ms |
2540 KB |
Output is correct |
63 |
Correct |
173 ms |
2528 KB |
Output is correct |
64 |
Correct |
142 ms |
2536 KB |
Output is correct |
65 |
Correct |
162 ms |
1956 KB |
Output is correct |
66 |
Correct |
168 ms |
2020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1088 KB |
Output is correct |
2 |
Correct |
3 ms |
1212 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
6 ms |
1424 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
4 ms |
1216 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
18 ms |
1548 KB |
Output is correct |
11 |
Correct |
13 ms |
1552 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
13 ms |
1548 KB |
Output is correct |
14 |
Correct |
12 ms |
1548 KB |
Output is correct |
15 |
Correct |
15 ms |
1548 KB |
Output is correct |
16 |
Correct |
14 ms |
1548 KB |
Output is correct |
17 |
Correct |
8 ms |
1472 KB |
Output is correct |
18 |
Correct |
14 ms |
1484 KB |
Output is correct |
19 |
Correct |
11 ms |
1548 KB |
Output is correct |
20 |
Correct |
12 ms |
1472 KB |
Output is correct |
21 |
Correct |
26 ms |
1664 KB |
Output is correct |
22 |
Correct |
30 ms |
1740 KB |
Output is correct |
23 |
Correct |
22 ms |
1652 KB |
Output is correct |
24 |
Correct |
44 ms |
1816 KB |
Output is correct |
25 |
Correct |
41 ms |
1784 KB |
Output is correct |
26 |
Correct |
42 ms |
1780 KB |
Output is correct |
27 |
Correct |
41 ms |
1740 KB |
Output is correct |
28 |
Correct |
45 ms |
1788 KB |
Output is correct |
29 |
Correct |
57 ms |
1788 KB |
Output is correct |
30 |
Correct |
41 ms |
1772 KB |
Output is correct |
31 |
Correct |
54 ms |
1772 KB |
Output is correct |
32 |
Correct |
44 ms |
1720 KB |
Output is correct |
33 |
Correct |
43 ms |
1740 KB |
Output is correct |
34 |
Correct |
54 ms |
1768 KB |
Output is correct |
35 |
Correct |
44 ms |
1776 KB |
Output is correct |
36 |
Correct |
59 ms |
1736 KB |
Output is correct |
37 |
Correct |
112 ms |
2028 KB |
Output is correct |
38 |
Correct |
97 ms |
2036 KB |
Output is correct |
39 |
Correct |
113 ms |
1976 KB |
Output is correct |
40 |
Correct |
128 ms |
2148 KB |
Output is correct |
41 |
Correct |
121 ms |
2020 KB |
Output is correct |
42 |
Correct |
112 ms |
2032 KB |
Output is correct |
43 |
Correct |
131 ms |
2280 KB |
Output is correct |
44 |
Correct |
112 ms |
2192 KB |
Output is correct |
45 |
Correct |
111 ms |
2236 KB |
Output is correct |
46 |
Correct |
134 ms |
1996 KB |
Output is correct |
47 |
Correct |
137 ms |
2024 KB |
Output is correct |
48 |
Correct |
113 ms |
2168 KB |
Output is correct |
49 |
Correct |
113 ms |
1900 KB |
Output is correct |
50 |
Correct |
121 ms |
2024 KB |
Output is correct |
51 |
Correct |
121 ms |
1900 KB |
Output is correct |
52 |
Correct |
121 ms |
2408 KB |
Output is correct |
53 |
Correct |
140 ms |
2276 KB |
Output is correct |
54 |
Correct |
172 ms |
2400 KB |
Output is correct |
55 |
Correct |
171 ms |
2536 KB |
Output is correct |
56 |
Correct |
140 ms |
2400 KB |
Output is correct |
57 |
Correct |
161 ms |
2664 KB |
Output is correct |
58 |
Correct |
196 ms |
2404 KB |
Output is correct |
59 |
Correct |
170 ms |
2536 KB |
Output is correct |
60 |
Correct |
159 ms |
2020 KB |
Output is correct |
61 |
Correct |
181 ms |
2532 KB |
Output is correct |
62 |
Correct |
156 ms |
2540 KB |
Output is correct |
63 |
Correct |
173 ms |
2528 KB |
Output is correct |
64 |
Correct |
142 ms |
2536 KB |
Output is correct |
65 |
Correct |
162 ms |
1956 KB |
Output is correct |
66 |
Correct |
168 ms |
2020 KB |
Output is correct |
67 |
Correct |
204 ms |
2532 KB |
Output is correct |
68 |
Correct |
256 ms |
1984 KB |
Output is correct |
69 |
Correct |
238 ms |
3172 KB |
Output is correct |
70 |
Correct |
260 ms |
2788 KB |
Output is correct |
71 |
Correct |
242 ms |
2724 KB |
Output is correct |
72 |
Correct |
267 ms |
2032 KB |
Output is correct |
73 |
Correct |
229 ms |
1952 KB |
Output is correct |
74 |
Correct |
235 ms |
3184 KB |
Output is correct |
75 |
Correct |
285 ms |
3048 KB |
Output is correct |
76 |
Correct |
250 ms |
3268 KB |
Output is correct |
77 |
Correct |
242 ms |
3300 KB |
Output is correct |