//Bismillahir-Rahmanir-Rahim
# include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x << " = " << x << endl;
# define pll pair <ll, ll>
# define pii pair <int, int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 5e2 + 3;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, a[maxn], sum;
int dp[maxn * maxn];
bitset <maxn * maxn> ok;
void add (int x) {
sum += x;
for (int i = sum - x; i >= 0; --i) {
dp[i + x] += dp[i];
}
}
void del (int x) {
for (int i = x; i <= sum; ++i) {
dp[i] -= dp[i - x];
}
sum -= x;
}
void ma1n (/* SABR */) {
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
add(a[i]);
}
if (sum & 1 || !dp[sum / 2]) {
cout << 0 << nl;
}
else {
for (int x = 1; x <= 250000; ++x) {
ok[x] = 1;
}
for (int i = 1; i <= n; ++i) {
del(a[i]);
for (int x = 1; x <= 250000; ++x){
if ((sum + x) & 1 || !dp[(sum + x) / 2]) {
ok[x] = 0;
}
}
add(a[i]);
}
cout << ok.count() << nl;
for (ll x = ok._Find_first(); x <= 250000; x = ok._Find_next(x)) {
cout << x << ' ';
}
cout << nl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; ++test) {
// cout << "Case " << test << ":" << '\n';
ma1n();
}
return 0;
}
// 998batrr | BbIWEJI 3A TObOU!!!
// tourist | BbIWEJI 3A TObOU!!!
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
340 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
340 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
15 ms |
376 KB |
Output is correct |
11 |
Correct |
15 ms |
340 KB |
Output is correct |
12 |
Correct |
15 ms |
340 KB |
Output is correct |
13 |
Correct |
13 ms |
368 KB |
Output is correct |
14 |
Correct |
14 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
368 KB |
Output is correct |
16 |
Correct |
15 ms |
340 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
13 ms |
340 KB |
Output is correct |
20 |
Correct |
15 ms |
368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
340 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
15 ms |
376 KB |
Output is correct |
11 |
Correct |
15 ms |
340 KB |
Output is correct |
12 |
Correct |
15 ms |
340 KB |
Output is correct |
13 |
Correct |
13 ms |
368 KB |
Output is correct |
14 |
Correct |
14 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
368 KB |
Output is correct |
16 |
Correct |
15 ms |
340 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
13 ms |
340 KB |
Output is correct |
20 |
Correct |
15 ms |
368 KB |
Output is correct |
21 |
Correct |
31 ms |
340 KB |
Output is correct |
22 |
Correct |
35 ms |
340 KB |
Output is correct |
23 |
Correct |
24 ms |
368 KB |
Output is correct |
24 |
Correct |
45 ms |
388 KB |
Output is correct |
25 |
Correct |
47 ms |
392 KB |
Output is correct |
26 |
Correct |
48 ms |
384 KB |
Output is correct |
27 |
Correct |
52 ms |
340 KB |
Output is correct |
28 |
Correct |
48 ms |
384 KB |
Output is correct |
29 |
Correct |
48 ms |
384 KB |
Output is correct |
30 |
Correct |
47 ms |
340 KB |
Output is correct |
31 |
Correct |
47 ms |
376 KB |
Output is correct |
32 |
Correct |
48 ms |
376 KB |
Output is correct |
33 |
Correct |
48 ms |
340 KB |
Output is correct |
34 |
Correct |
50 ms |
384 KB |
Output is correct |
35 |
Correct |
48 ms |
380 KB |
Output is correct |
36 |
Correct |
47 ms |
368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
340 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
15 ms |
376 KB |
Output is correct |
11 |
Correct |
15 ms |
340 KB |
Output is correct |
12 |
Correct |
15 ms |
340 KB |
Output is correct |
13 |
Correct |
13 ms |
368 KB |
Output is correct |
14 |
Correct |
14 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
368 KB |
Output is correct |
16 |
Correct |
15 ms |
340 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
13 ms |
340 KB |
Output is correct |
20 |
Correct |
15 ms |
368 KB |
Output is correct |
21 |
Correct |
31 ms |
340 KB |
Output is correct |
22 |
Correct |
35 ms |
340 KB |
Output is correct |
23 |
Correct |
24 ms |
368 KB |
Output is correct |
24 |
Correct |
45 ms |
388 KB |
Output is correct |
25 |
Correct |
47 ms |
392 KB |
Output is correct |
26 |
Correct |
48 ms |
384 KB |
Output is correct |
27 |
Correct |
52 ms |
340 KB |
Output is correct |
28 |
Correct |
48 ms |
384 KB |
Output is correct |
29 |
Correct |
48 ms |
384 KB |
Output is correct |
30 |
Correct |
47 ms |
340 KB |
Output is correct |
31 |
Correct |
47 ms |
376 KB |
Output is correct |
32 |
Correct |
48 ms |
376 KB |
Output is correct |
33 |
Correct |
48 ms |
340 KB |
Output is correct |
34 |
Correct |
50 ms |
384 KB |
Output is correct |
35 |
Correct |
48 ms |
380 KB |
Output is correct |
36 |
Correct |
47 ms |
368 KB |
Output is correct |
37 |
Correct |
97 ms |
428 KB |
Output is correct |
38 |
Correct |
95 ms |
424 KB |
Output is correct |
39 |
Correct |
132 ms |
596 KB |
Output is correct |
40 |
Correct |
129 ms |
492 KB |
Output is correct |
41 |
Correct |
147 ms |
596 KB |
Output is correct |
42 |
Correct |
122 ms |
468 KB |
Output is correct |
43 |
Correct |
119 ms |
704 KB |
Output is correct |
44 |
Correct |
123 ms |
700 KB |
Output is correct |
45 |
Correct |
122 ms |
700 KB |
Output is correct |
46 |
Correct |
139 ms |
468 KB |
Output is correct |
47 |
Correct |
120 ms |
480 KB |
Output is correct |
48 |
Correct |
125 ms |
600 KB |
Output is correct |
49 |
Correct |
131 ms |
592 KB |
Output is correct |
50 |
Correct |
119 ms |
492 KB |
Output is correct |
51 |
Correct |
2 ms |
340 KB |
Output is correct |
52 |
Correct |
144 ms |
752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
340 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
15 ms |
376 KB |
Output is correct |
11 |
Correct |
15 ms |
340 KB |
Output is correct |
12 |
Correct |
15 ms |
340 KB |
Output is correct |
13 |
Correct |
13 ms |
368 KB |
Output is correct |
14 |
Correct |
14 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
368 KB |
Output is correct |
16 |
Correct |
15 ms |
340 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
13 ms |
340 KB |
Output is correct |
20 |
Correct |
15 ms |
368 KB |
Output is correct |
21 |
Correct |
31 ms |
340 KB |
Output is correct |
22 |
Correct |
35 ms |
340 KB |
Output is correct |
23 |
Correct |
24 ms |
368 KB |
Output is correct |
24 |
Correct |
45 ms |
388 KB |
Output is correct |
25 |
Correct |
47 ms |
392 KB |
Output is correct |
26 |
Correct |
48 ms |
384 KB |
Output is correct |
27 |
Correct |
52 ms |
340 KB |
Output is correct |
28 |
Correct |
48 ms |
384 KB |
Output is correct |
29 |
Correct |
48 ms |
384 KB |
Output is correct |
30 |
Correct |
47 ms |
340 KB |
Output is correct |
31 |
Correct |
47 ms |
376 KB |
Output is correct |
32 |
Correct |
48 ms |
376 KB |
Output is correct |
33 |
Correct |
48 ms |
340 KB |
Output is correct |
34 |
Correct |
50 ms |
384 KB |
Output is correct |
35 |
Correct |
48 ms |
380 KB |
Output is correct |
36 |
Correct |
47 ms |
368 KB |
Output is correct |
37 |
Correct |
97 ms |
428 KB |
Output is correct |
38 |
Correct |
95 ms |
424 KB |
Output is correct |
39 |
Correct |
132 ms |
596 KB |
Output is correct |
40 |
Correct |
129 ms |
492 KB |
Output is correct |
41 |
Correct |
147 ms |
596 KB |
Output is correct |
42 |
Correct |
122 ms |
468 KB |
Output is correct |
43 |
Correct |
119 ms |
704 KB |
Output is correct |
44 |
Correct |
123 ms |
700 KB |
Output is correct |
45 |
Correct |
122 ms |
700 KB |
Output is correct |
46 |
Correct |
139 ms |
468 KB |
Output is correct |
47 |
Correct |
120 ms |
480 KB |
Output is correct |
48 |
Correct |
125 ms |
600 KB |
Output is correct |
49 |
Correct |
131 ms |
592 KB |
Output is correct |
50 |
Correct |
119 ms |
492 KB |
Output is correct |
51 |
Correct |
2 ms |
340 KB |
Output is correct |
52 |
Correct |
144 ms |
752 KB |
Output is correct |
53 |
Correct |
158 ms |
648 KB |
Output is correct |
54 |
Correct |
171 ms |
696 KB |
Output is correct |
55 |
Correct |
185 ms |
1044 KB |
Output is correct |
56 |
Correct |
162 ms |
692 KB |
Output is correct |
57 |
Correct |
191 ms |
1060 KB |
Output is correct |
58 |
Correct |
185 ms |
708 KB |
Output is correct |
59 |
Correct |
188 ms |
776 KB |
Output is correct |
60 |
Correct |
5 ms |
460 KB |
Output is correct |
61 |
Correct |
175 ms |
812 KB |
Output is correct |
62 |
Correct |
161 ms |
980 KB |
Output is correct |
63 |
Correct |
162 ms |
940 KB |
Output is correct |
64 |
Correct |
157 ms |
1016 KB |
Output is correct |
65 |
Correct |
163 ms |
532 KB |
Output is correct |
66 |
Correct |
161 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
340 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
15 ms |
376 KB |
Output is correct |
11 |
Correct |
15 ms |
340 KB |
Output is correct |
12 |
Correct |
15 ms |
340 KB |
Output is correct |
13 |
Correct |
13 ms |
368 KB |
Output is correct |
14 |
Correct |
14 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
368 KB |
Output is correct |
16 |
Correct |
15 ms |
340 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
13 ms |
340 KB |
Output is correct |
20 |
Correct |
15 ms |
368 KB |
Output is correct |
21 |
Correct |
31 ms |
340 KB |
Output is correct |
22 |
Correct |
35 ms |
340 KB |
Output is correct |
23 |
Correct |
24 ms |
368 KB |
Output is correct |
24 |
Correct |
45 ms |
388 KB |
Output is correct |
25 |
Correct |
47 ms |
392 KB |
Output is correct |
26 |
Correct |
48 ms |
384 KB |
Output is correct |
27 |
Correct |
52 ms |
340 KB |
Output is correct |
28 |
Correct |
48 ms |
384 KB |
Output is correct |
29 |
Correct |
48 ms |
384 KB |
Output is correct |
30 |
Correct |
47 ms |
340 KB |
Output is correct |
31 |
Correct |
47 ms |
376 KB |
Output is correct |
32 |
Correct |
48 ms |
376 KB |
Output is correct |
33 |
Correct |
48 ms |
340 KB |
Output is correct |
34 |
Correct |
50 ms |
384 KB |
Output is correct |
35 |
Correct |
48 ms |
380 KB |
Output is correct |
36 |
Correct |
47 ms |
368 KB |
Output is correct |
37 |
Correct |
97 ms |
428 KB |
Output is correct |
38 |
Correct |
95 ms |
424 KB |
Output is correct |
39 |
Correct |
132 ms |
596 KB |
Output is correct |
40 |
Correct |
129 ms |
492 KB |
Output is correct |
41 |
Correct |
147 ms |
596 KB |
Output is correct |
42 |
Correct |
122 ms |
468 KB |
Output is correct |
43 |
Correct |
119 ms |
704 KB |
Output is correct |
44 |
Correct |
123 ms |
700 KB |
Output is correct |
45 |
Correct |
122 ms |
700 KB |
Output is correct |
46 |
Correct |
139 ms |
468 KB |
Output is correct |
47 |
Correct |
120 ms |
480 KB |
Output is correct |
48 |
Correct |
125 ms |
600 KB |
Output is correct |
49 |
Correct |
131 ms |
592 KB |
Output is correct |
50 |
Correct |
119 ms |
492 KB |
Output is correct |
51 |
Correct |
2 ms |
340 KB |
Output is correct |
52 |
Correct |
144 ms |
752 KB |
Output is correct |
53 |
Correct |
158 ms |
648 KB |
Output is correct |
54 |
Correct |
171 ms |
696 KB |
Output is correct |
55 |
Correct |
185 ms |
1044 KB |
Output is correct |
56 |
Correct |
162 ms |
692 KB |
Output is correct |
57 |
Correct |
191 ms |
1060 KB |
Output is correct |
58 |
Correct |
185 ms |
708 KB |
Output is correct |
59 |
Correct |
188 ms |
776 KB |
Output is correct |
60 |
Correct |
5 ms |
460 KB |
Output is correct |
61 |
Correct |
175 ms |
812 KB |
Output is correct |
62 |
Correct |
161 ms |
980 KB |
Output is correct |
63 |
Correct |
162 ms |
940 KB |
Output is correct |
64 |
Correct |
157 ms |
1016 KB |
Output is correct |
65 |
Correct |
163 ms |
532 KB |
Output is correct |
66 |
Correct |
161 ms |
556 KB |
Output is correct |
67 |
Correct |
193 ms |
788 KB |
Output is correct |
68 |
Correct |
14 ms |
732 KB |
Output is correct |
69 |
Correct |
271 ms |
1816 KB |
Output is correct |
70 |
Correct |
257 ms |
1240 KB |
Output is correct |
71 |
Correct |
255 ms |
1220 KB |
Output is correct |
72 |
Correct |
258 ms |
836 KB |
Output is correct |
73 |
Correct |
249 ms |
832 KB |
Output is correct |
74 |
Correct |
272 ms |
1864 KB |
Output is correct |
75 |
Correct |
261 ms |
1544 KB |
Output is correct |
76 |
Correct |
281 ms |
1944 KB |
Output is correct |
77 |
Correct |
291 ms |
1928 KB |
Output is correct |