//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define low_b lower_bound
#define endl "\n"
//#define int long long
using namespace std;
void dout() {
cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << H << ' ';
dout(T...);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
const int N = 353, M = 122501;
int n, a[N];
bitset <M> sack, res, ans;
void solve(int tc) {
// check for (int i = 0; i < n; j++)
cin >> n;
int total = 0;
sack[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
total += a[i];
sack |= (sack << a[i]);
}
if ((total & 1) || !sack[total >> 1]) {
cout << 0;
return;
}
int cur;
ans.set();
for (int i = 1; i <= n; i++) {
sack.reset();
res.reset();
sack[0] = 1;
for (int j = 1; j <= n; j++) {
if (i == j) {
continue;
}
sack |= (sack << a[j]);
}
cur = total - a[i];
for (int j = cur & 1; j <= cur; j += 2) {
if (sack[cur + j >> 1] || sack[cur - j >> 1]) {
res[j] = 1;
}
}
ans &= res;
}
cout << ans.count() << endl;
for (int i = 0; i < M; i++) {
if (ans[i]) {
cout << i << " ";
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tc = 1;
// cin >> tc;
for (int i = 0; i < tc; i++) {
solve(i);
// cleanup();
}
}
Compilation message
bootfall.cpp: In function 'void solve(int)':
bootfall.cpp:71:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if (sack[cur + j >> 1] || sack[cur - j >> 1]) {
~~~~^~~
bootfall.cpp:71:48: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
if (sack[cur + j >> 1] || sack[cur - j >> 1]) {
~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
452 KB |
Output is correct |
20 |
Correct |
7 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
452 KB |
Output is correct |
20 |
Correct |
7 ms |
380 KB |
Output is correct |
21 |
Correct |
26 ms |
380 KB |
Output is correct |
22 |
Correct |
37 ms |
376 KB |
Output is correct |
23 |
Correct |
17 ms |
416 KB |
Output is correct |
24 |
Correct |
54 ms |
504 KB |
Output is correct |
25 |
Correct |
55 ms |
504 KB |
Output is correct |
26 |
Correct |
61 ms |
376 KB |
Output is correct |
27 |
Correct |
65 ms |
376 KB |
Output is correct |
28 |
Correct |
62 ms |
504 KB |
Output is correct |
29 |
Correct |
62 ms |
376 KB |
Output is correct |
30 |
Correct |
60 ms |
376 KB |
Output is correct |
31 |
Correct |
62 ms |
376 KB |
Output is correct |
32 |
Correct |
60 ms |
376 KB |
Output is correct |
33 |
Correct |
61 ms |
376 KB |
Output is correct |
34 |
Correct |
61 ms |
376 KB |
Output is correct |
35 |
Correct |
62 ms |
376 KB |
Output is correct |
36 |
Correct |
61 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
452 KB |
Output is correct |
20 |
Correct |
7 ms |
380 KB |
Output is correct |
21 |
Correct |
26 ms |
380 KB |
Output is correct |
22 |
Correct |
37 ms |
376 KB |
Output is correct |
23 |
Correct |
17 ms |
416 KB |
Output is correct |
24 |
Correct |
54 ms |
504 KB |
Output is correct |
25 |
Correct |
55 ms |
504 KB |
Output is correct |
26 |
Correct |
61 ms |
376 KB |
Output is correct |
27 |
Correct |
65 ms |
376 KB |
Output is correct |
28 |
Correct |
62 ms |
504 KB |
Output is correct |
29 |
Correct |
62 ms |
376 KB |
Output is correct |
30 |
Correct |
60 ms |
376 KB |
Output is correct |
31 |
Correct |
62 ms |
376 KB |
Output is correct |
32 |
Correct |
60 ms |
376 KB |
Output is correct |
33 |
Correct |
61 ms |
376 KB |
Output is correct |
34 |
Correct |
61 ms |
376 KB |
Output is correct |
35 |
Correct |
62 ms |
376 KB |
Output is correct |
36 |
Correct |
61 ms |
376 KB |
Output is correct |
37 |
Correct |
241 ms |
480 KB |
Output is correct |
38 |
Correct |
240 ms |
456 KB |
Output is correct |
39 |
Correct |
408 ms |
508 KB |
Output is correct |
40 |
Correct |
437 ms |
444 KB |
Output is correct |
41 |
Correct |
452 ms |
504 KB |
Output is correct |
42 |
Correct |
379 ms |
508 KB |
Output is correct |
43 |
Correct |
365 ms |
580 KB |
Output is correct |
44 |
Correct |
381 ms |
504 KB |
Output is correct |
45 |
Correct |
384 ms |
580 KB |
Output is correct |
46 |
Correct |
430 ms |
504 KB |
Output is correct |
47 |
Correct |
380 ms |
456 KB |
Output is correct |
48 |
Correct |
386 ms |
504 KB |
Output is correct |
49 |
Correct |
382 ms |
448 KB |
Output is correct |
50 |
Correct |
376 ms |
504 KB |
Output is correct |
51 |
Correct |
4 ms |
376 KB |
Output is correct |
52 |
Correct |
465 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
452 KB |
Output is correct |
20 |
Correct |
7 ms |
380 KB |
Output is correct |
21 |
Correct |
26 ms |
380 KB |
Output is correct |
22 |
Correct |
37 ms |
376 KB |
Output is correct |
23 |
Correct |
17 ms |
416 KB |
Output is correct |
24 |
Correct |
54 ms |
504 KB |
Output is correct |
25 |
Correct |
55 ms |
504 KB |
Output is correct |
26 |
Correct |
61 ms |
376 KB |
Output is correct |
27 |
Correct |
65 ms |
376 KB |
Output is correct |
28 |
Correct |
62 ms |
504 KB |
Output is correct |
29 |
Correct |
62 ms |
376 KB |
Output is correct |
30 |
Correct |
60 ms |
376 KB |
Output is correct |
31 |
Correct |
62 ms |
376 KB |
Output is correct |
32 |
Correct |
60 ms |
376 KB |
Output is correct |
33 |
Correct |
61 ms |
376 KB |
Output is correct |
34 |
Correct |
61 ms |
376 KB |
Output is correct |
35 |
Correct |
62 ms |
376 KB |
Output is correct |
36 |
Correct |
61 ms |
376 KB |
Output is correct |
37 |
Correct |
241 ms |
480 KB |
Output is correct |
38 |
Correct |
240 ms |
456 KB |
Output is correct |
39 |
Correct |
408 ms |
508 KB |
Output is correct |
40 |
Correct |
437 ms |
444 KB |
Output is correct |
41 |
Correct |
452 ms |
504 KB |
Output is correct |
42 |
Correct |
379 ms |
508 KB |
Output is correct |
43 |
Correct |
365 ms |
580 KB |
Output is correct |
44 |
Correct |
381 ms |
504 KB |
Output is correct |
45 |
Correct |
384 ms |
580 KB |
Output is correct |
46 |
Correct |
430 ms |
504 KB |
Output is correct |
47 |
Correct |
380 ms |
456 KB |
Output is correct |
48 |
Correct |
386 ms |
504 KB |
Output is correct |
49 |
Correct |
382 ms |
448 KB |
Output is correct |
50 |
Correct |
376 ms |
504 KB |
Output is correct |
51 |
Correct |
4 ms |
376 KB |
Output is correct |
52 |
Correct |
465 ms |
632 KB |
Output is correct |
53 |
Correct |
538 ms |
580 KB |
Output is correct |
54 |
Correct |
722 ms |
632 KB |
Output is correct |
55 |
Correct |
760 ms |
760 KB |
Output is correct |
56 |
Correct |
576 ms |
632 KB |
Output is correct |
57 |
Correct |
777 ms |
760 KB |
Output is correct |
58 |
Correct |
741 ms |
632 KB |
Output is correct |
59 |
Correct |
752 ms |
632 KB |
Output is correct |
60 |
Correct |
4 ms |
376 KB |
Output is correct |
61 |
Correct |
742 ms |
632 KB |
Output is correct |
62 |
Correct |
642 ms |
760 KB |
Output is correct |
63 |
Correct |
648 ms |
760 KB |
Output is correct |
64 |
Correct |
613 ms |
760 KB |
Output is correct |
65 |
Correct |
633 ms |
504 KB |
Output is correct |
66 |
Correct |
588 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
8 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
452 KB |
Output is correct |
20 |
Correct |
7 ms |
380 KB |
Output is correct |
21 |
Correct |
26 ms |
380 KB |
Output is correct |
22 |
Correct |
37 ms |
376 KB |
Output is correct |
23 |
Correct |
17 ms |
416 KB |
Output is correct |
24 |
Correct |
54 ms |
504 KB |
Output is correct |
25 |
Correct |
55 ms |
504 KB |
Output is correct |
26 |
Correct |
61 ms |
376 KB |
Output is correct |
27 |
Correct |
65 ms |
376 KB |
Output is correct |
28 |
Correct |
62 ms |
504 KB |
Output is correct |
29 |
Correct |
62 ms |
376 KB |
Output is correct |
30 |
Correct |
60 ms |
376 KB |
Output is correct |
31 |
Correct |
62 ms |
376 KB |
Output is correct |
32 |
Correct |
60 ms |
376 KB |
Output is correct |
33 |
Correct |
61 ms |
376 KB |
Output is correct |
34 |
Correct |
61 ms |
376 KB |
Output is correct |
35 |
Correct |
62 ms |
376 KB |
Output is correct |
36 |
Correct |
61 ms |
376 KB |
Output is correct |
37 |
Correct |
241 ms |
480 KB |
Output is correct |
38 |
Correct |
240 ms |
456 KB |
Output is correct |
39 |
Correct |
408 ms |
508 KB |
Output is correct |
40 |
Correct |
437 ms |
444 KB |
Output is correct |
41 |
Correct |
452 ms |
504 KB |
Output is correct |
42 |
Correct |
379 ms |
508 KB |
Output is correct |
43 |
Correct |
365 ms |
580 KB |
Output is correct |
44 |
Correct |
381 ms |
504 KB |
Output is correct |
45 |
Correct |
384 ms |
580 KB |
Output is correct |
46 |
Correct |
430 ms |
504 KB |
Output is correct |
47 |
Correct |
380 ms |
456 KB |
Output is correct |
48 |
Correct |
386 ms |
504 KB |
Output is correct |
49 |
Correct |
382 ms |
448 KB |
Output is correct |
50 |
Correct |
376 ms |
504 KB |
Output is correct |
51 |
Correct |
4 ms |
376 KB |
Output is correct |
52 |
Correct |
465 ms |
632 KB |
Output is correct |
53 |
Correct |
538 ms |
580 KB |
Output is correct |
54 |
Correct |
722 ms |
632 KB |
Output is correct |
55 |
Correct |
760 ms |
760 KB |
Output is correct |
56 |
Correct |
576 ms |
632 KB |
Output is correct |
57 |
Correct |
777 ms |
760 KB |
Output is correct |
58 |
Correct |
741 ms |
632 KB |
Output is correct |
59 |
Correct |
752 ms |
632 KB |
Output is correct |
60 |
Correct |
4 ms |
376 KB |
Output is correct |
61 |
Correct |
742 ms |
632 KB |
Output is correct |
62 |
Correct |
642 ms |
760 KB |
Output is correct |
63 |
Correct |
648 ms |
760 KB |
Output is correct |
64 |
Correct |
613 ms |
760 KB |
Output is correct |
65 |
Correct |
633 ms |
504 KB |
Output is correct |
66 |
Correct |
588 ms |
420 KB |
Output is correct |
67 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |