#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 998244353;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 250001;
void backpack(bitset<N> &can, vec<int> &a, int l, int r)
{
can.reset();
can[0] = 1;
for (int i = l; i <= r; i++) can |= can << a[i];
}
void solve()
{
int n;
cin >> n;
vec<int> a(n + 1);
int s = 0;
for (int i = 1; i <= n; i++) cin >> a[i], s += a[i];
bitset<N> base, start, end;
backpack(base, a, 1, n);
if (!base[s / 2])
{
cout << 0;
return;
}
backpack(start, a, 1, n / 2);
backpack(end, a, n / 2 + 1, n);
vec<int> cnt(500 * n + 1);
for (int i = 1; i <= n; i++)
{
bitset<N> can;
if (i <= n / 2)
{
can = end;
for (int j = 1; j <= n / 2; j++) if (j != i) can |= can << a[j];
}
else
{
can = start;
for (int j = n / 2 + 1; j <= n; j++) if (j != i) can |= can << a[j];
}
int from = (s - a[i]) % 2 ? 1 : 2;
for (int j = from; j <= 500 * n; j += 2)
{
if (can[(s - a[i] + j) / 2]) cnt[j]++;
}
}
vec<int> ans;
for (int i = 1; i <= 500 * n; i++) if (cnt[i] == n) ans.pb(i);
cout << sz(ans) << "\n";
for (int &x : ans) cout << x << " ";
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
624 KB |
Output is correct |
12 |
Correct |
4 ms |
624 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
500 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
3 ms |
500 KB |
Output is correct |
20 |
Correct |
4 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
624 KB |
Output is correct |
12 |
Correct |
4 ms |
624 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
500 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
3 ms |
500 KB |
Output is correct |
20 |
Correct |
4 ms |
596 KB |
Output is correct |
21 |
Correct |
12 ms |
596 KB |
Output is correct |
22 |
Correct |
17 ms |
724 KB |
Output is correct |
23 |
Correct |
12 ms |
596 KB |
Output is correct |
24 |
Correct |
26 ms |
752 KB |
Output is correct |
25 |
Correct |
25 ms |
756 KB |
Output is correct |
26 |
Correct |
33 ms |
768 KB |
Output is correct |
27 |
Correct |
30 ms |
760 KB |
Output is correct |
28 |
Correct |
32 ms |
760 KB |
Output is correct |
29 |
Correct |
29 ms |
760 KB |
Output is correct |
30 |
Correct |
28 ms |
756 KB |
Output is correct |
31 |
Correct |
28 ms |
724 KB |
Output is correct |
32 |
Correct |
29 ms |
768 KB |
Output is correct |
33 |
Correct |
28 ms |
724 KB |
Output is correct |
34 |
Correct |
28 ms |
724 KB |
Output is correct |
35 |
Correct |
39 ms |
724 KB |
Output is correct |
36 |
Correct |
28 ms |
752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
624 KB |
Output is correct |
12 |
Correct |
4 ms |
624 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
500 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
3 ms |
500 KB |
Output is correct |
20 |
Correct |
4 ms |
596 KB |
Output is correct |
21 |
Correct |
12 ms |
596 KB |
Output is correct |
22 |
Correct |
17 ms |
724 KB |
Output is correct |
23 |
Correct |
12 ms |
596 KB |
Output is correct |
24 |
Correct |
26 ms |
752 KB |
Output is correct |
25 |
Correct |
25 ms |
756 KB |
Output is correct |
26 |
Correct |
33 ms |
768 KB |
Output is correct |
27 |
Correct |
30 ms |
760 KB |
Output is correct |
28 |
Correct |
32 ms |
760 KB |
Output is correct |
29 |
Correct |
29 ms |
760 KB |
Output is correct |
30 |
Correct |
28 ms |
756 KB |
Output is correct |
31 |
Correct |
28 ms |
724 KB |
Output is correct |
32 |
Correct |
29 ms |
768 KB |
Output is correct |
33 |
Correct |
28 ms |
724 KB |
Output is correct |
34 |
Correct |
28 ms |
724 KB |
Output is correct |
35 |
Correct |
39 ms |
724 KB |
Output is correct |
36 |
Correct |
28 ms |
752 KB |
Output is correct |
37 |
Correct |
114 ms |
1084 KB |
Output is correct |
38 |
Correct |
115 ms |
1080 KB |
Output is correct |
39 |
Correct |
177 ms |
1044 KB |
Output is correct |
40 |
Correct |
204 ms |
1212 KB |
Output is correct |
41 |
Correct |
228 ms |
1080 KB |
Output is correct |
42 |
Correct |
188 ms |
1180 KB |
Output is correct |
43 |
Correct |
168 ms |
1420 KB |
Output is correct |
44 |
Correct |
171 ms |
1432 KB |
Output is correct |
45 |
Correct |
172 ms |
1432 KB |
Output is correct |
46 |
Correct |
203 ms |
980 KB |
Output is correct |
47 |
Correct |
175 ms |
1176 KB |
Output is correct |
48 |
Correct |
186 ms |
1300 KB |
Output is correct |
49 |
Correct |
174 ms |
1048 KB |
Output is correct |
50 |
Correct |
177 ms |
1176 KB |
Output is correct |
51 |
Correct |
177 ms |
1012 KB |
Output is correct |
52 |
Correct |
212 ms |
1468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
624 KB |
Output is correct |
12 |
Correct |
4 ms |
624 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
500 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
3 ms |
500 KB |
Output is correct |
20 |
Correct |
4 ms |
596 KB |
Output is correct |
21 |
Correct |
12 ms |
596 KB |
Output is correct |
22 |
Correct |
17 ms |
724 KB |
Output is correct |
23 |
Correct |
12 ms |
596 KB |
Output is correct |
24 |
Correct |
26 ms |
752 KB |
Output is correct |
25 |
Correct |
25 ms |
756 KB |
Output is correct |
26 |
Correct |
33 ms |
768 KB |
Output is correct |
27 |
Correct |
30 ms |
760 KB |
Output is correct |
28 |
Correct |
32 ms |
760 KB |
Output is correct |
29 |
Correct |
29 ms |
760 KB |
Output is correct |
30 |
Correct |
28 ms |
756 KB |
Output is correct |
31 |
Correct |
28 ms |
724 KB |
Output is correct |
32 |
Correct |
29 ms |
768 KB |
Output is correct |
33 |
Correct |
28 ms |
724 KB |
Output is correct |
34 |
Correct |
28 ms |
724 KB |
Output is correct |
35 |
Correct |
39 ms |
724 KB |
Output is correct |
36 |
Correct |
28 ms |
752 KB |
Output is correct |
37 |
Correct |
114 ms |
1084 KB |
Output is correct |
38 |
Correct |
115 ms |
1080 KB |
Output is correct |
39 |
Correct |
177 ms |
1044 KB |
Output is correct |
40 |
Correct |
204 ms |
1212 KB |
Output is correct |
41 |
Correct |
228 ms |
1080 KB |
Output is correct |
42 |
Correct |
188 ms |
1180 KB |
Output is correct |
43 |
Correct |
168 ms |
1420 KB |
Output is correct |
44 |
Correct |
171 ms |
1432 KB |
Output is correct |
45 |
Correct |
172 ms |
1432 KB |
Output is correct |
46 |
Correct |
203 ms |
980 KB |
Output is correct |
47 |
Correct |
175 ms |
1176 KB |
Output is correct |
48 |
Correct |
186 ms |
1300 KB |
Output is correct |
49 |
Correct |
174 ms |
1048 KB |
Output is correct |
50 |
Correct |
177 ms |
1176 KB |
Output is correct |
51 |
Correct |
177 ms |
1012 KB |
Output is correct |
52 |
Correct |
212 ms |
1468 KB |
Output is correct |
53 |
Correct |
248 ms |
1404 KB |
Output is correct |
54 |
Correct |
349 ms |
1628 KB |
Output is correct |
55 |
Correct |
336 ms |
1756 KB |
Output is correct |
56 |
Correct |
264 ms |
1544 KB |
Output is correct |
57 |
Correct |
339 ms |
1888 KB |
Output is correct |
58 |
Correct |
339 ms |
1632 KB |
Output is correct |
59 |
Correct |
337 ms |
1704 KB |
Output is correct |
60 |
Correct |
341 ms |
1236 KB |
Output is correct |
61 |
Correct |
348 ms |
1756 KB |
Output is correct |
62 |
Correct |
287 ms |
1744 KB |
Output is correct |
63 |
Correct |
302 ms |
1696 KB |
Output is correct |
64 |
Correct |
272 ms |
1700 KB |
Output is correct |
65 |
Correct |
272 ms |
1184 KB |
Output is correct |
66 |
Correct |
262 ms |
1164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
624 KB |
Output is correct |
12 |
Correct |
4 ms |
624 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
500 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
3 ms |
500 KB |
Output is correct |
20 |
Correct |
4 ms |
596 KB |
Output is correct |
21 |
Correct |
12 ms |
596 KB |
Output is correct |
22 |
Correct |
17 ms |
724 KB |
Output is correct |
23 |
Correct |
12 ms |
596 KB |
Output is correct |
24 |
Correct |
26 ms |
752 KB |
Output is correct |
25 |
Correct |
25 ms |
756 KB |
Output is correct |
26 |
Correct |
33 ms |
768 KB |
Output is correct |
27 |
Correct |
30 ms |
760 KB |
Output is correct |
28 |
Correct |
32 ms |
760 KB |
Output is correct |
29 |
Correct |
29 ms |
760 KB |
Output is correct |
30 |
Correct |
28 ms |
756 KB |
Output is correct |
31 |
Correct |
28 ms |
724 KB |
Output is correct |
32 |
Correct |
29 ms |
768 KB |
Output is correct |
33 |
Correct |
28 ms |
724 KB |
Output is correct |
34 |
Correct |
28 ms |
724 KB |
Output is correct |
35 |
Correct |
39 ms |
724 KB |
Output is correct |
36 |
Correct |
28 ms |
752 KB |
Output is correct |
37 |
Correct |
114 ms |
1084 KB |
Output is correct |
38 |
Correct |
115 ms |
1080 KB |
Output is correct |
39 |
Correct |
177 ms |
1044 KB |
Output is correct |
40 |
Correct |
204 ms |
1212 KB |
Output is correct |
41 |
Correct |
228 ms |
1080 KB |
Output is correct |
42 |
Correct |
188 ms |
1180 KB |
Output is correct |
43 |
Correct |
168 ms |
1420 KB |
Output is correct |
44 |
Correct |
171 ms |
1432 KB |
Output is correct |
45 |
Correct |
172 ms |
1432 KB |
Output is correct |
46 |
Correct |
203 ms |
980 KB |
Output is correct |
47 |
Correct |
175 ms |
1176 KB |
Output is correct |
48 |
Correct |
186 ms |
1300 KB |
Output is correct |
49 |
Correct |
174 ms |
1048 KB |
Output is correct |
50 |
Correct |
177 ms |
1176 KB |
Output is correct |
51 |
Correct |
177 ms |
1012 KB |
Output is correct |
52 |
Correct |
212 ms |
1468 KB |
Output is correct |
53 |
Correct |
248 ms |
1404 KB |
Output is correct |
54 |
Correct |
349 ms |
1628 KB |
Output is correct |
55 |
Correct |
336 ms |
1756 KB |
Output is correct |
56 |
Correct |
264 ms |
1544 KB |
Output is correct |
57 |
Correct |
339 ms |
1888 KB |
Output is correct |
58 |
Correct |
339 ms |
1632 KB |
Output is correct |
59 |
Correct |
337 ms |
1704 KB |
Output is correct |
60 |
Correct |
341 ms |
1236 KB |
Output is correct |
61 |
Correct |
348 ms |
1756 KB |
Output is correct |
62 |
Correct |
287 ms |
1744 KB |
Output is correct |
63 |
Correct |
302 ms |
1696 KB |
Output is correct |
64 |
Correct |
272 ms |
1700 KB |
Output is correct |
65 |
Correct |
272 ms |
1184 KB |
Output is correct |
66 |
Correct |
262 ms |
1164 KB |
Output is correct |
67 |
Correct |
459 ms |
1776 KB |
Output is correct |
68 |
Correct |
4 ms |
468 KB |
Output is correct |
69 |
Correct |
720 ms |
2680 KB |
Output is correct |
70 |
Correct |
705 ms |
2192 KB |
Output is correct |
71 |
Correct |
691 ms |
2256 KB |
Output is correct |
72 |
Correct |
700 ms |
1492 KB |
Output is correct |
73 |
Correct |
688 ms |
1492 KB |
Output is correct |
74 |
Correct |
704 ms |
2680 KB |
Output is correct |
75 |
Correct |
705 ms |
2552 KB |
Output is correct |
76 |
Correct |
700 ms |
2688 KB |
Output is correct |
77 |
Correct |
763 ms |
2812 KB |
Output is correct |