#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); }
int mod = 433494437;
int total = 0;
vi pol2;
int add(int a, int b) {
int res = (a + b) % mod;
return res < 0 ? res + mod : res;
}
int ct[250001];
void divide(int d, int sh) {
vii changes;
for(int i = total; i - d >= 0 && i - d + sh >= total / 2; i--) {
if(pol2[i] != 0) {
changes.eb(i - d, pol2[i - d]);
pol2[i - d] = add(pol2[i - d], -pol2[i]);
ct[i - d + sh] += 1;
}
}
for(ii p: changes)
pol2[p.F] = p.S;
}
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));
bool odd = true, even = true;
for(int a: arr) {
total += a;
if(a % 2)
even = false;
else
odd = false;
}
pol2.assign(total + 1, 0);
pol2[0] = 1;
for(int a: arr) {
for(int i = total - a; i >= 0; i--) {
pol2[i + a] = add(pol2[i + a], pol2[i]);
}
}
if(total % 2 || pol2[total / 2] == 0 || (!even && !odd))
{
cout << 0;
return;
}
int tt = sz(nums);
for(int a: nums) {
int d = (a + (odd ? 1 : 0)) / 2;
divide(a, d);
}
vi vans;
int rem = (odd ? 1 : 0) + total;
forbn(i, (rem + 1) / 2, total + 1) {
if(ct[i] == tt) {
vans.pb(2 * i - rem);
}
}
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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
360 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
6 ms |
352 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
364 KB |
Output is correct |
34 |
Correct |
6 ms |
360 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
360 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
6 ms |
352 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
364 KB |
Output is correct |
34 |
Correct |
6 ms |
360 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
344 KB |
Output is correct |
37 |
Correct |
27 ms |
644 KB |
Output is correct |
38 |
Correct |
26 ms |
660 KB |
Output is correct |
39 |
Correct |
74 ms |
572 KB |
Output is correct |
40 |
Correct |
69 ms |
704 KB |
Output is correct |
41 |
Correct |
109 ms |
736 KB |
Output is correct |
42 |
Correct |
63 ms |
740 KB |
Output is correct |
43 |
Correct |
74 ms |
1100 KB |
Output is correct |
44 |
Correct |
78 ms |
1120 KB |
Output is correct |
45 |
Correct |
82 ms |
1128 KB |
Output is correct |
46 |
Correct |
53 ms |
560 KB |
Output is correct |
47 |
Correct |
65 ms |
776 KB |
Output is correct |
48 |
Correct |
83 ms |
1092 KB |
Output is correct |
49 |
Correct |
76 ms |
856 KB |
Output is correct |
50 |
Correct |
66 ms |
692 KB |
Output is correct |
51 |
Correct |
42 ms |
440 KB |
Output is correct |
52 |
Correct |
103 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
360 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
6 ms |
352 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
364 KB |
Output is correct |
34 |
Correct |
6 ms |
360 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
344 KB |
Output is correct |
37 |
Correct |
27 ms |
644 KB |
Output is correct |
38 |
Correct |
26 ms |
660 KB |
Output is correct |
39 |
Correct |
74 ms |
572 KB |
Output is correct |
40 |
Correct |
69 ms |
704 KB |
Output is correct |
41 |
Correct |
109 ms |
736 KB |
Output is correct |
42 |
Correct |
63 ms |
740 KB |
Output is correct |
43 |
Correct |
74 ms |
1100 KB |
Output is correct |
44 |
Correct |
78 ms |
1120 KB |
Output is correct |
45 |
Correct |
82 ms |
1128 KB |
Output is correct |
46 |
Correct |
53 ms |
560 KB |
Output is correct |
47 |
Correct |
65 ms |
776 KB |
Output is correct |
48 |
Correct |
83 ms |
1092 KB |
Output is correct |
49 |
Correct |
76 ms |
856 KB |
Output is correct |
50 |
Correct |
66 ms |
692 KB |
Output is correct |
51 |
Correct |
42 ms |
440 KB |
Output is correct |
52 |
Correct |
103 ms |
1228 KB |
Output is correct |
53 |
Correct |
109 ms |
1024 KB |
Output is correct |
54 |
Correct |
147 ms |
1132 KB |
Output is correct |
55 |
Correct |
204 ms |
1888 KB |
Output is correct |
56 |
Correct |
138 ms |
1240 KB |
Output is correct |
57 |
Correct |
223 ms |
1920 KB |
Output is correct |
58 |
Correct |
185 ms |
1520 KB |
Output is correct |
59 |
Correct |
208 ms |
1792 KB |
Output is correct |
60 |
Correct |
102 ms |
468 KB |
Output is correct |
61 |
Correct |
220 ms |
1672 KB |
Output is correct |
62 |
Correct |
193 ms |
1752 KB |
Output is correct |
63 |
Correct |
181 ms |
1832 KB |
Output is correct |
64 |
Correct |
187 ms |
1796 KB |
Output is correct |
65 |
Correct |
78 ms |
516 KB |
Output is correct |
66 |
Correct |
85 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
360 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
6 ms |
352 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
364 KB |
Output is correct |
34 |
Correct |
6 ms |
360 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
344 KB |
Output is correct |
37 |
Correct |
27 ms |
644 KB |
Output is correct |
38 |
Correct |
26 ms |
660 KB |
Output is correct |
39 |
Correct |
74 ms |
572 KB |
Output is correct |
40 |
Correct |
69 ms |
704 KB |
Output is correct |
41 |
Correct |
109 ms |
736 KB |
Output is correct |
42 |
Correct |
63 ms |
740 KB |
Output is correct |
43 |
Correct |
74 ms |
1100 KB |
Output is correct |
44 |
Correct |
78 ms |
1120 KB |
Output is correct |
45 |
Correct |
82 ms |
1128 KB |
Output is correct |
46 |
Correct |
53 ms |
560 KB |
Output is correct |
47 |
Correct |
65 ms |
776 KB |
Output is correct |
48 |
Correct |
83 ms |
1092 KB |
Output is correct |
49 |
Correct |
76 ms |
856 KB |
Output is correct |
50 |
Correct |
66 ms |
692 KB |
Output is correct |
51 |
Correct |
42 ms |
440 KB |
Output is correct |
52 |
Correct |
103 ms |
1228 KB |
Output is correct |
53 |
Correct |
109 ms |
1024 KB |
Output is correct |
54 |
Correct |
147 ms |
1132 KB |
Output is correct |
55 |
Correct |
204 ms |
1888 KB |
Output is correct |
56 |
Correct |
138 ms |
1240 KB |
Output is correct |
57 |
Correct |
223 ms |
1920 KB |
Output is correct |
58 |
Correct |
185 ms |
1520 KB |
Output is correct |
59 |
Correct |
208 ms |
1792 KB |
Output is correct |
60 |
Correct |
102 ms |
468 KB |
Output is correct |
61 |
Correct |
220 ms |
1672 KB |
Output is correct |
62 |
Correct |
193 ms |
1752 KB |
Output is correct |
63 |
Correct |
181 ms |
1832 KB |
Output is correct |
64 |
Correct |
187 ms |
1796 KB |
Output is correct |
65 |
Correct |
78 ms |
516 KB |
Output is correct |
66 |
Correct |
85 ms |
652 KB |
Output is correct |
67 |
Correct |
286 ms |
1864 KB |
Output is correct |
68 |
Correct |
318 ms |
724 KB |
Output is correct |
69 |
Correct |
581 ms |
3476 KB |
Output is correct |
70 |
Correct |
523 ms |
2300 KB |
Output is correct |
71 |
Correct |
522 ms |
2068 KB |
Output is correct |
72 |
Correct |
329 ms |
852 KB |
Output is correct |
73 |
Correct |
300 ms |
840 KB |
Output is correct |
74 |
Correct |
656 ms |
3576 KB |
Output is correct |
75 |
Correct |
637 ms |
3184 KB |
Output is correct |
76 |
Correct |
652 ms |
3684 KB |
Output is correct |
77 |
Correct |
650 ms |
3600 KB |
Output is correct |