#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define lc v << 1
#define rc (v << 1) + 1
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef complex<double> cd;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }
const int BASE = 500;
const int MX = BASE * BASE + 1;
using bts = bitset<MX>;
int pr2 = 479001599;
int add(int a, int b, int mod) {
return ((a + b) % mod + mod) % mod;
}
bts divide(vi pol2, int d) {
bts res;
for(int i = 0; i + d < MX; i++) {
if(pol2[i] != 0) {
pol2[i + d] = add(pol2[i + d], -pol2[i], pr2);
res[i] = 1;
}
}
return res;
}
void solve() {
int n;
cin >> n;
vi arr(n);
set<int> nums;
forn(i, n) {
cin >> arr[i];
nums.insert(arr[i]);
}
sort(all(arr));
vi pol2(MX, 0);
pol2[0] = 1;
for(int a: arr) {
for(int i = MX - a - 1; i >= 0; i--) {
pol2[i + a] = add(pol2[i + a], pol2[i], pr2);
}
}
bts s;
s[0] = 1;
int total = 0;
bool odd = true, even = true;
for(int a: arr) {
s |= s << a;
total += a;
if(a % 2)
even = false;
else
odd = false;
}
if(total % 2 || s[total / 2] == 0 || (!even && !odd))
{
cout << 0;
return;
}
bts ans;
ans.flip();
for(int a: nums) {
bts c = divide(pol2, a);
int d = (total - a - (odd ? 1 : 0)) / 2;
ans &= c >> d;
}
vi vans;
forbn(i, 1, MX) {
if(ans[i]) {
vans.pb(2 * i - (odd ? 1 : 0));
}
}
cout << sz(vans) << '\n';
for(int el: vans)
cout << el << ' ';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// freopen("triangles.in", "r", stdin);
// freopen("triangles.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2432 KB |
Output is correct |
2 |
Correct |
19 ms |
2392 KB |
Output is correct |
3 |
Correct |
9 ms |
1364 KB |
Output is correct |
4 |
Correct |
12 ms |
2352 KB |
Output is correct |
5 |
Correct |
37 ms |
2380 KB |
Output is correct |
6 |
Correct |
24 ms |
2392 KB |
Output is correct |
7 |
Correct |
19 ms |
2432 KB |
Output is correct |
8 |
Correct |
34 ms |
2400 KB |
Output is correct |
9 |
Correct |
28 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2432 KB |
Output is correct |
2 |
Correct |
19 ms |
2392 KB |
Output is correct |
3 |
Correct |
9 ms |
1364 KB |
Output is correct |
4 |
Correct |
12 ms |
2352 KB |
Output is correct |
5 |
Correct |
37 ms |
2380 KB |
Output is correct |
6 |
Correct |
24 ms |
2392 KB |
Output is correct |
7 |
Correct |
19 ms |
2432 KB |
Output is correct |
8 |
Correct |
34 ms |
2400 KB |
Output is correct |
9 |
Correct |
28 ms |
1364 KB |
Output is correct |
10 |
Correct |
83 ms |
2332 KB |
Output is correct |
11 |
Correct |
85 ms |
2376 KB |
Output is correct |
12 |
Correct |
84 ms |
2380 KB |
Output is correct |
13 |
Correct |
71 ms |
1364 KB |
Output is correct |
14 |
Correct |
78 ms |
2388 KB |
Output is correct |
15 |
Correct |
78 ms |
2380 KB |
Output is correct |
16 |
Correct |
84 ms |
2380 KB |
Output is correct |
17 |
Correct |
51 ms |
2376 KB |
Output is correct |
18 |
Correct |
67 ms |
2380 KB |
Output is correct |
19 |
Correct |
73 ms |
2380 KB |
Output is correct |
20 |
Correct |
78 ms |
2344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2432 KB |
Output is correct |
2 |
Correct |
19 ms |
2392 KB |
Output is correct |
3 |
Correct |
9 ms |
1364 KB |
Output is correct |
4 |
Correct |
12 ms |
2352 KB |
Output is correct |
5 |
Correct |
37 ms |
2380 KB |
Output is correct |
6 |
Correct |
24 ms |
2392 KB |
Output is correct |
7 |
Correct |
19 ms |
2432 KB |
Output is correct |
8 |
Correct |
34 ms |
2400 KB |
Output is correct |
9 |
Correct |
28 ms |
1364 KB |
Output is correct |
10 |
Correct |
83 ms |
2332 KB |
Output is correct |
11 |
Correct |
85 ms |
2376 KB |
Output is correct |
12 |
Correct |
84 ms |
2380 KB |
Output is correct |
13 |
Correct |
71 ms |
1364 KB |
Output is correct |
14 |
Correct |
78 ms |
2388 KB |
Output is correct |
15 |
Correct |
78 ms |
2380 KB |
Output is correct |
16 |
Correct |
84 ms |
2380 KB |
Output is correct |
17 |
Correct |
51 ms |
2376 KB |
Output is correct |
18 |
Correct |
67 ms |
2380 KB |
Output is correct |
19 |
Correct |
73 ms |
2380 KB |
Output is correct |
20 |
Correct |
78 ms |
2344 KB |
Output is correct |
21 |
Correct |
181 ms |
2384 KB |
Output is correct |
22 |
Correct |
207 ms |
2380 KB |
Output is correct |
23 |
Correct |
142 ms |
2372 KB |
Output is correct |
24 |
Correct |
259 ms |
2384 KB |
Output is correct |
25 |
Correct |
254 ms |
2372 KB |
Output is correct |
26 |
Correct |
268 ms |
2380 KB |
Output is correct |
27 |
Correct |
270 ms |
2380 KB |
Output is correct |
28 |
Correct |
272 ms |
2376 KB |
Output is correct |
29 |
Correct |
272 ms |
2384 KB |
Output is correct |
30 |
Correct |
270 ms |
1420 KB |
Output is correct |
31 |
Correct |
277 ms |
2424 KB |
Output is correct |
32 |
Correct |
274 ms |
2384 KB |
Output is correct |
33 |
Correct |
269 ms |
2328 KB |
Output is correct |
34 |
Correct |
266 ms |
2332 KB |
Output is correct |
35 |
Correct |
267 ms |
2380 KB |
Output is correct |
36 |
Correct |
273 ms |
2376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2432 KB |
Output is correct |
2 |
Correct |
19 ms |
2392 KB |
Output is correct |
3 |
Correct |
9 ms |
1364 KB |
Output is correct |
4 |
Correct |
12 ms |
2352 KB |
Output is correct |
5 |
Correct |
37 ms |
2380 KB |
Output is correct |
6 |
Correct |
24 ms |
2392 KB |
Output is correct |
7 |
Correct |
19 ms |
2432 KB |
Output is correct |
8 |
Correct |
34 ms |
2400 KB |
Output is correct |
9 |
Correct |
28 ms |
1364 KB |
Output is correct |
10 |
Correct |
83 ms |
2332 KB |
Output is correct |
11 |
Correct |
85 ms |
2376 KB |
Output is correct |
12 |
Correct |
84 ms |
2380 KB |
Output is correct |
13 |
Correct |
71 ms |
1364 KB |
Output is correct |
14 |
Correct |
78 ms |
2388 KB |
Output is correct |
15 |
Correct |
78 ms |
2380 KB |
Output is correct |
16 |
Correct |
84 ms |
2380 KB |
Output is correct |
17 |
Correct |
51 ms |
2376 KB |
Output is correct |
18 |
Correct |
67 ms |
2380 KB |
Output is correct |
19 |
Correct |
73 ms |
2380 KB |
Output is correct |
20 |
Correct |
78 ms |
2344 KB |
Output is correct |
21 |
Correct |
181 ms |
2384 KB |
Output is correct |
22 |
Correct |
207 ms |
2380 KB |
Output is correct |
23 |
Correct |
142 ms |
2372 KB |
Output is correct |
24 |
Correct |
259 ms |
2384 KB |
Output is correct |
25 |
Correct |
254 ms |
2372 KB |
Output is correct |
26 |
Correct |
268 ms |
2380 KB |
Output is correct |
27 |
Correct |
270 ms |
2380 KB |
Output is correct |
28 |
Correct |
272 ms |
2376 KB |
Output is correct |
29 |
Correct |
272 ms |
2384 KB |
Output is correct |
30 |
Correct |
270 ms |
1420 KB |
Output is correct |
31 |
Correct |
277 ms |
2424 KB |
Output is correct |
32 |
Correct |
274 ms |
2384 KB |
Output is correct |
33 |
Correct |
269 ms |
2328 KB |
Output is correct |
34 |
Correct |
266 ms |
2332 KB |
Output is correct |
35 |
Correct |
267 ms |
2380 KB |
Output is correct |
36 |
Correct |
273 ms |
2376 KB |
Output is correct |
37 |
Correct |
554 ms |
2388 KB |
Output is correct |
38 |
Correct |
551 ms |
2384 KB |
Output is correct |
39 |
Correct |
662 ms |
2340 KB |
Output is correct |
40 |
Correct |
780 ms |
2512 KB |
Output is correct |
41 |
Correct |
721 ms |
2340 KB |
Output is correct |
42 |
Correct |
720 ms |
2388 KB |
Output is correct |
43 |
Correct |
669 ms |
2508 KB |
Output is correct |
44 |
Correct |
684 ms |
2544 KB |
Output is correct |
45 |
Correct |
685 ms |
2504 KB |
Output is correct |
46 |
Correct |
769 ms |
2388 KB |
Output is correct |
47 |
Correct |
718 ms |
2512 KB |
Output is correct |
48 |
Correct |
672 ms |
2508 KB |
Output is correct |
49 |
Correct |
675 ms |
2380 KB |
Output is correct |
50 |
Correct |
740 ms |
2504 KB |
Output is correct |
51 |
Correct |
669 ms |
1364 KB |
Output is correct |
52 |
Correct |
729 ms |
2504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2432 KB |
Output is correct |
2 |
Correct |
19 ms |
2392 KB |
Output is correct |
3 |
Correct |
9 ms |
1364 KB |
Output is correct |
4 |
Correct |
12 ms |
2352 KB |
Output is correct |
5 |
Correct |
37 ms |
2380 KB |
Output is correct |
6 |
Correct |
24 ms |
2392 KB |
Output is correct |
7 |
Correct |
19 ms |
2432 KB |
Output is correct |
8 |
Correct |
34 ms |
2400 KB |
Output is correct |
9 |
Correct |
28 ms |
1364 KB |
Output is correct |
10 |
Correct |
83 ms |
2332 KB |
Output is correct |
11 |
Correct |
85 ms |
2376 KB |
Output is correct |
12 |
Correct |
84 ms |
2380 KB |
Output is correct |
13 |
Correct |
71 ms |
1364 KB |
Output is correct |
14 |
Correct |
78 ms |
2388 KB |
Output is correct |
15 |
Correct |
78 ms |
2380 KB |
Output is correct |
16 |
Correct |
84 ms |
2380 KB |
Output is correct |
17 |
Correct |
51 ms |
2376 KB |
Output is correct |
18 |
Correct |
67 ms |
2380 KB |
Output is correct |
19 |
Correct |
73 ms |
2380 KB |
Output is correct |
20 |
Correct |
78 ms |
2344 KB |
Output is correct |
21 |
Correct |
181 ms |
2384 KB |
Output is correct |
22 |
Correct |
207 ms |
2380 KB |
Output is correct |
23 |
Correct |
142 ms |
2372 KB |
Output is correct |
24 |
Correct |
259 ms |
2384 KB |
Output is correct |
25 |
Correct |
254 ms |
2372 KB |
Output is correct |
26 |
Correct |
268 ms |
2380 KB |
Output is correct |
27 |
Correct |
270 ms |
2380 KB |
Output is correct |
28 |
Correct |
272 ms |
2376 KB |
Output is correct |
29 |
Correct |
272 ms |
2384 KB |
Output is correct |
30 |
Correct |
270 ms |
1420 KB |
Output is correct |
31 |
Correct |
277 ms |
2424 KB |
Output is correct |
32 |
Correct |
274 ms |
2384 KB |
Output is correct |
33 |
Correct |
269 ms |
2328 KB |
Output is correct |
34 |
Correct |
266 ms |
2332 KB |
Output is correct |
35 |
Correct |
267 ms |
2380 KB |
Output is correct |
36 |
Correct |
273 ms |
2376 KB |
Output is correct |
37 |
Correct |
554 ms |
2388 KB |
Output is correct |
38 |
Correct |
551 ms |
2384 KB |
Output is correct |
39 |
Correct |
662 ms |
2340 KB |
Output is correct |
40 |
Correct |
780 ms |
2512 KB |
Output is correct |
41 |
Correct |
721 ms |
2340 KB |
Output is correct |
42 |
Correct |
720 ms |
2388 KB |
Output is correct |
43 |
Correct |
669 ms |
2508 KB |
Output is correct |
44 |
Correct |
684 ms |
2544 KB |
Output is correct |
45 |
Correct |
685 ms |
2504 KB |
Output is correct |
46 |
Correct |
769 ms |
2388 KB |
Output is correct |
47 |
Correct |
718 ms |
2512 KB |
Output is correct |
48 |
Correct |
672 ms |
2508 KB |
Output is correct |
49 |
Correct |
675 ms |
2380 KB |
Output is correct |
50 |
Correct |
740 ms |
2504 KB |
Output is correct |
51 |
Correct |
669 ms |
1364 KB |
Output is correct |
52 |
Correct |
729 ms |
2504 KB |
Output is correct |
53 |
Correct |
875 ms |
2512 KB |
Output is correct |
54 |
Execution timed out |
1010 ms |
2524 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2432 KB |
Output is correct |
2 |
Correct |
19 ms |
2392 KB |
Output is correct |
3 |
Correct |
9 ms |
1364 KB |
Output is correct |
4 |
Correct |
12 ms |
2352 KB |
Output is correct |
5 |
Correct |
37 ms |
2380 KB |
Output is correct |
6 |
Correct |
24 ms |
2392 KB |
Output is correct |
7 |
Correct |
19 ms |
2432 KB |
Output is correct |
8 |
Correct |
34 ms |
2400 KB |
Output is correct |
9 |
Correct |
28 ms |
1364 KB |
Output is correct |
10 |
Correct |
83 ms |
2332 KB |
Output is correct |
11 |
Correct |
85 ms |
2376 KB |
Output is correct |
12 |
Correct |
84 ms |
2380 KB |
Output is correct |
13 |
Correct |
71 ms |
1364 KB |
Output is correct |
14 |
Correct |
78 ms |
2388 KB |
Output is correct |
15 |
Correct |
78 ms |
2380 KB |
Output is correct |
16 |
Correct |
84 ms |
2380 KB |
Output is correct |
17 |
Correct |
51 ms |
2376 KB |
Output is correct |
18 |
Correct |
67 ms |
2380 KB |
Output is correct |
19 |
Correct |
73 ms |
2380 KB |
Output is correct |
20 |
Correct |
78 ms |
2344 KB |
Output is correct |
21 |
Correct |
181 ms |
2384 KB |
Output is correct |
22 |
Correct |
207 ms |
2380 KB |
Output is correct |
23 |
Correct |
142 ms |
2372 KB |
Output is correct |
24 |
Correct |
259 ms |
2384 KB |
Output is correct |
25 |
Correct |
254 ms |
2372 KB |
Output is correct |
26 |
Correct |
268 ms |
2380 KB |
Output is correct |
27 |
Correct |
270 ms |
2380 KB |
Output is correct |
28 |
Correct |
272 ms |
2376 KB |
Output is correct |
29 |
Correct |
272 ms |
2384 KB |
Output is correct |
30 |
Correct |
270 ms |
1420 KB |
Output is correct |
31 |
Correct |
277 ms |
2424 KB |
Output is correct |
32 |
Correct |
274 ms |
2384 KB |
Output is correct |
33 |
Correct |
269 ms |
2328 KB |
Output is correct |
34 |
Correct |
266 ms |
2332 KB |
Output is correct |
35 |
Correct |
267 ms |
2380 KB |
Output is correct |
36 |
Correct |
273 ms |
2376 KB |
Output is correct |
37 |
Correct |
554 ms |
2388 KB |
Output is correct |
38 |
Correct |
551 ms |
2384 KB |
Output is correct |
39 |
Correct |
662 ms |
2340 KB |
Output is correct |
40 |
Correct |
780 ms |
2512 KB |
Output is correct |
41 |
Correct |
721 ms |
2340 KB |
Output is correct |
42 |
Correct |
720 ms |
2388 KB |
Output is correct |
43 |
Correct |
669 ms |
2508 KB |
Output is correct |
44 |
Correct |
684 ms |
2544 KB |
Output is correct |
45 |
Correct |
685 ms |
2504 KB |
Output is correct |
46 |
Correct |
769 ms |
2388 KB |
Output is correct |
47 |
Correct |
718 ms |
2512 KB |
Output is correct |
48 |
Correct |
672 ms |
2508 KB |
Output is correct |
49 |
Correct |
675 ms |
2380 KB |
Output is correct |
50 |
Correct |
740 ms |
2504 KB |
Output is correct |
51 |
Correct |
669 ms |
1364 KB |
Output is correct |
52 |
Correct |
729 ms |
2504 KB |
Output is correct |
53 |
Correct |
875 ms |
2512 KB |
Output is correct |
54 |
Execution timed out |
1010 ms |
2524 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |