#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#define test(x...) abc("[" + string(#x) + "]", x);
const int N = 500 * 500 + 5, C = 23;
bitset <N> dp;
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector <int> a(n);
int sum = 0;
dp.flip(0);
for (int i = 0; i < n; ++i) {
cin >> a[i];
sum += a[i];
dp |= dp << a[i];
}
if (sum & 1 || !dp[sum >> 1]) {
cout << 0 << endl << endl;
} else {
vector <int> ans(N, 0);
for (int i = 0; i < n; i += C) {
int to = min(i + C, n);
dp.reset(), dp.flip(0);
for (int j = 0; j < i; ++j)
dp |= dp << a[j];
for (int j = to; j < n; ++j)
dp |= dp << a[j];
for (int j = i; j < to; ++j) {
auto cur = dp;
for (int k = i; k < to; ++k) if (k ^ j)
cur |= cur << a[k];
for (int i = 0; i <= (sum - a[j]) / 2; ++i) if (cur[i])
ans[abs(sum - a[j] - i - i)]++;
}
}
int cnt = 0;
for (int i : ans) if (i == n)
cnt++;
cout << cnt << endl;
for (int i = 0; i < N; ++i) if (ans[i] == n)
cout << i << ' ';
cout << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
2 ms |
1312 KB |
Output is correct |
7 |
Correct |
2 ms |
1356 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
2 ms |
1312 KB |
Output is correct |
7 |
Correct |
2 ms |
1356 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
7 ms |
1416 KB |
Output is correct |
12 |
Correct |
5 ms |
1356 KB |
Output is correct |
13 |
Correct |
5 ms |
1356 KB |
Output is correct |
14 |
Correct |
5 ms |
1424 KB |
Output is correct |
15 |
Correct |
6 ms |
1420 KB |
Output is correct |
16 |
Correct |
5 ms |
1368 KB |
Output is correct |
17 |
Correct |
5 ms |
1356 KB |
Output is correct |
18 |
Correct |
5 ms |
1356 KB |
Output is correct |
19 |
Correct |
5 ms |
1356 KB |
Output is correct |
20 |
Correct |
5 ms |
1428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
2 ms |
1312 KB |
Output is correct |
7 |
Correct |
2 ms |
1356 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
7 ms |
1416 KB |
Output is correct |
12 |
Correct |
5 ms |
1356 KB |
Output is correct |
13 |
Correct |
5 ms |
1356 KB |
Output is correct |
14 |
Correct |
5 ms |
1424 KB |
Output is correct |
15 |
Correct |
6 ms |
1420 KB |
Output is correct |
16 |
Correct |
5 ms |
1368 KB |
Output is correct |
17 |
Correct |
5 ms |
1356 KB |
Output is correct |
18 |
Correct |
5 ms |
1356 KB |
Output is correct |
19 |
Correct |
5 ms |
1356 KB |
Output is correct |
20 |
Correct |
5 ms |
1428 KB |
Output is correct |
21 |
Correct |
12 ms |
1420 KB |
Output is correct |
22 |
Correct |
15 ms |
1424 KB |
Output is correct |
23 |
Correct |
10 ms |
1428 KB |
Output is correct |
24 |
Correct |
21 ms |
1412 KB |
Output is correct |
25 |
Correct |
22 ms |
1416 KB |
Output is correct |
26 |
Correct |
29 ms |
1416 KB |
Output is correct |
27 |
Correct |
23 ms |
1408 KB |
Output is correct |
28 |
Correct |
28 ms |
1412 KB |
Output is correct |
29 |
Correct |
23 ms |
1424 KB |
Output is correct |
30 |
Correct |
22 ms |
1356 KB |
Output is correct |
31 |
Correct |
24 ms |
1356 KB |
Output is correct |
32 |
Correct |
29 ms |
1412 KB |
Output is correct |
33 |
Correct |
21 ms |
1356 KB |
Output is correct |
34 |
Correct |
20 ms |
1408 KB |
Output is correct |
35 |
Correct |
30 ms |
1364 KB |
Output is correct |
36 |
Correct |
21 ms |
1440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
2 ms |
1312 KB |
Output is correct |
7 |
Correct |
2 ms |
1356 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
7 ms |
1416 KB |
Output is correct |
12 |
Correct |
5 ms |
1356 KB |
Output is correct |
13 |
Correct |
5 ms |
1356 KB |
Output is correct |
14 |
Correct |
5 ms |
1424 KB |
Output is correct |
15 |
Correct |
6 ms |
1420 KB |
Output is correct |
16 |
Correct |
5 ms |
1368 KB |
Output is correct |
17 |
Correct |
5 ms |
1356 KB |
Output is correct |
18 |
Correct |
5 ms |
1356 KB |
Output is correct |
19 |
Correct |
5 ms |
1356 KB |
Output is correct |
20 |
Correct |
5 ms |
1428 KB |
Output is correct |
21 |
Correct |
12 ms |
1420 KB |
Output is correct |
22 |
Correct |
15 ms |
1424 KB |
Output is correct |
23 |
Correct |
10 ms |
1428 KB |
Output is correct |
24 |
Correct |
21 ms |
1412 KB |
Output is correct |
25 |
Correct |
22 ms |
1416 KB |
Output is correct |
26 |
Correct |
29 ms |
1416 KB |
Output is correct |
27 |
Correct |
23 ms |
1408 KB |
Output is correct |
28 |
Correct |
28 ms |
1412 KB |
Output is correct |
29 |
Correct |
23 ms |
1424 KB |
Output is correct |
30 |
Correct |
22 ms |
1356 KB |
Output is correct |
31 |
Correct |
24 ms |
1356 KB |
Output is correct |
32 |
Correct |
29 ms |
1412 KB |
Output is correct |
33 |
Correct |
21 ms |
1356 KB |
Output is correct |
34 |
Correct |
20 ms |
1408 KB |
Output is correct |
35 |
Correct |
30 ms |
1364 KB |
Output is correct |
36 |
Correct |
21 ms |
1440 KB |
Output is correct |
37 |
Correct |
55 ms |
1412 KB |
Output is correct |
38 |
Correct |
66 ms |
1412 KB |
Output is correct |
39 |
Correct |
71 ms |
1408 KB |
Output is correct |
40 |
Correct |
97 ms |
1400 KB |
Output is correct |
41 |
Correct |
82 ms |
1400 KB |
Output is correct |
42 |
Correct |
95 ms |
1404 KB |
Output is correct |
43 |
Correct |
98 ms |
1524 KB |
Output is correct |
44 |
Correct |
106 ms |
1532 KB |
Output is correct |
45 |
Correct |
115 ms |
1528 KB |
Output is correct |
46 |
Correct |
84 ms |
1356 KB |
Output is correct |
47 |
Correct |
96 ms |
1408 KB |
Output is correct |
48 |
Correct |
114 ms |
1400 KB |
Output is correct |
49 |
Correct |
103 ms |
1412 KB |
Output is correct |
50 |
Correct |
96 ms |
1412 KB |
Output is correct |
51 |
Correct |
3 ms |
332 KB |
Output is correct |
52 |
Correct |
118 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
2 ms |
1312 KB |
Output is correct |
7 |
Correct |
2 ms |
1356 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
7 ms |
1416 KB |
Output is correct |
12 |
Correct |
5 ms |
1356 KB |
Output is correct |
13 |
Correct |
5 ms |
1356 KB |
Output is correct |
14 |
Correct |
5 ms |
1424 KB |
Output is correct |
15 |
Correct |
6 ms |
1420 KB |
Output is correct |
16 |
Correct |
5 ms |
1368 KB |
Output is correct |
17 |
Correct |
5 ms |
1356 KB |
Output is correct |
18 |
Correct |
5 ms |
1356 KB |
Output is correct |
19 |
Correct |
5 ms |
1356 KB |
Output is correct |
20 |
Correct |
5 ms |
1428 KB |
Output is correct |
21 |
Correct |
12 ms |
1420 KB |
Output is correct |
22 |
Correct |
15 ms |
1424 KB |
Output is correct |
23 |
Correct |
10 ms |
1428 KB |
Output is correct |
24 |
Correct |
21 ms |
1412 KB |
Output is correct |
25 |
Correct |
22 ms |
1416 KB |
Output is correct |
26 |
Correct |
29 ms |
1416 KB |
Output is correct |
27 |
Correct |
23 ms |
1408 KB |
Output is correct |
28 |
Correct |
28 ms |
1412 KB |
Output is correct |
29 |
Correct |
23 ms |
1424 KB |
Output is correct |
30 |
Correct |
22 ms |
1356 KB |
Output is correct |
31 |
Correct |
24 ms |
1356 KB |
Output is correct |
32 |
Correct |
29 ms |
1412 KB |
Output is correct |
33 |
Correct |
21 ms |
1356 KB |
Output is correct |
34 |
Correct |
20 ms |
1408 KB |
Output is correct |
35 |
Correct |
30 ms |
1364 KB |
Output is correct |
36 |
Correct |
21 ms |
1440 KB |
Output is correct |
37 |
Correct |
55 ms |
1412 KB |
Output is correct |
38 |
Correct |
66 ms |
1412 KB |
Output is correct |
39 |
Correct |
71 ms |
1408 KB |
Output is correct |
40 |
Correct |
97 ms |
1400 KB |
Output is correct |
41 |
Correct |
82 ms |
1400 KB |
Output is correct |
42 |
Correct |
95 ms |
1404 KB |
Output is correct |
43 |
Correct |
98 ms |
1524 KB |
Output is correct |
44 |
Correct |
106 ms |
1532 KB |
Output is correct |
45 |
Correct |
115 ms |
1528 KB |
Output is correct |
46 |
Correct |
84 ms |
1356 KB |
Output is correct |
47 |
Correct |
96 ms |
1408 KB |
Output is correct |
48 |
Correct |
114 ms |
1400 KB |
Output is correct |
49 |
Correct |
103 ms |
1412 KB |
Output is correct |
50 |
Correct |
96 ms |
1412 KB |
Output is correct |
51 |
Correct |
3 ms |
332 KB |
Output is correct |
52 |
Correct |
118 ms |
1528 KB |
Output is correct |
53 |
Correct |
163 ms |
1528 KB |
Output is correct |
54 |
Correct |
206 ms |
1528 KB |
Output is correct |
55 |
Correct |
209 ms |
1664 KB |
Output is correct |
56 |
Correct |
145 ms |
1532 KB |
Output is correct |
57 |
Correct |
220 ms |
1656 KB |
Output is correct |
58 |
Correct |
176 ms |
1524 KB |
Output is correct |
59 |
Correct |
232 ms |
1536 KB |
Output is correct |
60 |
Correct |
5 ms |
332 KB |
Output is correct |
61 |
Correct |
215 ms |
1532 KB |
Output is correct |
62 |
Correct |
177 ms |
1656 KB |
Output is correct |
63 |
Correct |
186 ms |
1652 KB |
Output is correct |
64 |
Correct |
196 ms |
1660 KB |
Output is correct |
65 |
Correct |
103 ms |
1404 KB |
Output is correct |
66 |
Correct |
101 ms |
1412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1356 KB |
Output is correct |
6 |
Correct |
2 ms |
1312 KB |
Output is correct |
7 |
Correct |
2 ms |
1356 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
7 ms |
1416 KB |
Output is correct |
12 |
Correct |
5 ms |
1356 KB |
Output is correct |
13 |
Correct |
5 ms |
1356 KB |
Output is correct |
14 |
Correct |
5 ms |
1424 KB |
Output is correct |
15 |
Correct |
6 ms |
1420 KB |
Output is correct |
16 |
Correct |
5 ms |
1368 KB |
Output is correct |
17 |
Correct |
5 ms |
1356 KB |
Output is correct |
18 |
Correct |
5 ms |
1356 KB |
Output is correct |
19 |
Correct |
5 ms |
1356 KB |
Output is correct |
20 |
Correct |
5 ms |
1428 KB |
Output is correct |
21 |
Correct |
12 ms |
1420 KB |
Output is correct |
22 |
Correct |
15 ms |
1424 KB |
Output is correct |
23 |
Correct |
10 ms |
1428 KB |
Output is correct |
24 |
Correct |
21 ms |
1412 KB |
Output is correct |
25 |
Correct |
22 ms |
1416 KB |
Output is correct |
26 |
Correct |
29 ms |
1416 KB |
Output is correct |
27 |
Correct |
23 ms |
1408 KB |
Output is correct |
28 |
Correct |
28 ms |
1412 KB |
Output is correct |
29 |
Correct |
23 ms |
1424 KB |
Output is correct |
30 |
Correct |
22 ms |
1356 KB |
Output is correct |
31 |
Correct |
24 ms |
1356 KB |
Output is correct |
32 |
Correct |
29 ms |
1412 KB |
Output is correct |
33 |
Correct |
21 ms |
1356 KB |
Output is correct |
34 |
Correct |
20 ms |
1408 KB |
Output is correct |
35 |
Correct |
30 ms |
1364 KB |
Output is correct |
36 |
Correct |
21 ms |
1440 KB |
Output is correct |
37 |
Correct |
55 ms |
1412 KB |
Output is correct |
38 |
Correct |
66 ms |
1412 KB |
Output is correct |
39 |
Correct |
71 ms |
1408 KB |
Output is correct |
40 |
Correct |
97 ms |
1400 KB |
Output is correct |
41 |
Correct |
82 ms |
1400 KB |
Output is correct |
42 |
Correct |
95 ms |
1404 KB |
Output is correct |
43 |
Correct |
98 ms |
1524 KB |
Output is correct |
44 |
Correct |
106 ms |
1532 KB |
Output is correct |
45 |
Correct |
115 ms |
1528 KB |
Output is correct |
46 |
Correct |
84 ms |
1356 KB |
Output is correct |
47 |
Correct |
96 ms |
1408 KB |
Output is correct |
48 |
Correct |
114 ms |
1400 KB |
Output is correct |
49 |
Correct |
103 ms |
1412 KB |
Output is correct |
50 |
Correct |
96 ms |
1412 KB |
Output is correct |
51 |
Correct |
3 ms |
332 KB |
Output is correct |
52 |
Correct |
118 ms |
1528 KB |
Output is correct |
53 |
Correct |
163 ms |
1528 KB |
Output is correct |
54 |
Correct |
206 ms |
1528 KB |
Output is correct |
55 |
Correct |
209 ms |
1664 KB |
Output is correct |
56 |
Correct |
145 ms |
1532 KB |
Output is correct |
57 |
Correct |
220 ms |
1656 KB |
Output is correct |
58 |
Correct |
176 ms |
1524 KB |
Output is correct |
59 |
Correct |
232 ms |
1536 KB |
Output is correct |
60 |
Correct |
5 ms |
332 KB |
Output is correct |
61 |
Correct |
215 ms |
1532 KB |
Output is correct |
62 |
Correct |
177 ms |
1656 KB |
Output is correct |
63 |
Correct |
186 ms |
1652 KB |
Output is correct |
64 |
Correct |
196 ms |
1660 KB |
Output is correct |
65 |
Correct |
103 ms |
1404 KB |
Output is correct |
66 |
Correct |
101 ms |
1412 KB |
Output is correct |
67 |
Correct |
253 ms |
1528 KB |
Output is correct |
68 |
Correct |
7 ms |
332 KB |
Output is correct |
69 |
Correct |
473 ms |
2044 KB |
Output is correct |
70 |
Correct |
334 ms |
1788 KB |
Output is correct |
71 |
Correct |
356 ms |
1684 KB |
Output is correct |
72 |
Correct |
339 ms |
1408 KB |
Output is correct |
73 |
Correct |
339 ms |
1400 KB |
Output is correct |
74 |
Correct |
481 ms |
2036 KB |
Output is correct |
75 |
Correct |
420 ms |
1920 KB |
Output is correct |
76 |
Correct |
472 ms |
2040 KB |
Output is correct |
77 |
Correct |
508 ms |
2040 KB |
Output is correct |