//stupid solution 1
#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define forn(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using ld = long double;
const int N = 500 + 7;
const int NN = N * N;
const ll mod = 1e9 + 7;
const ll inf = 2e18;
auto ra = [] {char *p = new char ; delete p ; return ll(p) ; };
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (ra() | 1));
int n;
int ret[NN];
vi a;
bitset<NN> pref[N], suff[N];
void eval(bitset<NN> &ret, int l, int r, int d)
{
if (d == 1)
for (int i = l; i <= r; ++i)
ret |= (ret << a[i]);
else
for (int i = r; i >= l; --i)
ret |= (ret << a[i]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("in.in", "r", stdin);
cin >> n;
vi ans;
a.resize(n);
int sum = 0;
for (auto &u : a)
cin >> u;
sum = accumulate(a.begin(), a.end(), 0);
bitset<NN> ini, ini2;
ini[0] = ini2[0] = 1;
for (int i = 0; i < n; ++i)
{
ini |= (ini << a[i]);
ini2 |= (ini2 << a[n - 1 - i]);
suff[n - 1 - i] = ini2;
pref[i] = ini;
}
if (sum & 1 || !pref[n - 1][sum / 2])
return cout << 0, 0;
for (int i = 0; i < n; ++i)
{
int sm = sum - a[i];
int lhs = i, rhs = n - 1 - i;
bitset<NN> bts;
if (lhs > rhs)
{
if (i)
bts = pref[i - 1];
eval(bts, i + 1, n - 1, 1);
}
else
{
if (i + 1 < n)
bts = suff[i + 1];
eval(bts, 0, i - 1, -1);
}
for (int j = 0; j <= sm; ++j)
{
if (bts[j])
{
if (2 * j != sm)
ret[abs(j - (sm - j))]++;
}
}
}
int sz = 0;
for (int u = 1; u < NN; ++u)
{
if (ret[u] == 2 * n)
ans.push_back(u);
}
cout << (int)ans.size() << "\n";
for (auto u : ans)
cout << u << " ";
return 0;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:99:13: warning: unused variable 'sz' [-Wunused-variable]
99 | int sz = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
876 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
1260 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
1260 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
876 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
1260 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
1260 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
4 ms |
2412 KB |
Output is correct |
11 |
Correct |
4 ms |
2412 KB |
Output is correct |
12 |
Correct |
4 ms |
2412 KB |
Output is correct |
13 |
Correct |
4 ms |
2156 KB |
Output is correct |
14 |
Correct |
5 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2284 KB |
Output is correct |
16 |
Correct |
4 ms |
2412 KB |
Output is correct |
17 |
Correct |
3 ms |
1644 KB |
Output is correct |
18 |
Correct |
4 ms |
2028 KB |
Output is correct |
19 |
Correct |
4 ms |
2156 KB |
Output is correct |
20 |
Correct |
5 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
876 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
1260 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
1260 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
4 ms |
2412 KB |
Output is correct |
11 |
Correct |
4 ms |
2412 KB |
Output is correct |
12 |
Correct |
4 ms |
2412 KB |
Output is correct |
13 |
Correct |
4 ms |
2156 KB |
Output is correct |
14 |
Correct |
5 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2284 KB |
Output is correct |
16 |
Correct |
4 ms |
2412 KB |
Output is correct |
17 |
Correct |
3 ms |
1644 KB |
Output is correct |
18 |
Correct |
4 ms |
2028 KB |
Output is correct |
19 |
Correct |
4 ms |
2156 KB |
Output is correct |
20 |
Correct |
5 ms |
2432 KB |
Output is correct |
21 |
Correct |
12 ms |
4588 KB |
Output is correct |
22 |
Correct |
20 ms |
5228 KB |
Output is correct |
23 |
Correct |
8 ms |
3692 KB |
Output is correct |
24 |
Correct |
24 ms |
6508 KB |
Output is correct |
25 |
Correct |
26 ms |
6508 KB |
Output is correct |
26 |
Correct |
27 ms |
6892 KB |
Output is correct |
27 |
Correct |
26 ms |
6892 KB |
Output is correct |
28 |
Correct |
32 ms |
7020 KB |
Output is correct |
29 |
Correct |
27 ms |
6892 KB |
Output is correct |
30 |
Correct |
26 ms |
6764 KB |
Output is correct |
31 |
Correct |
27 ms |
6892 KB |
Output is correct |
32 |
Correct |
26 ms |
6892 KB |
Output is correct |
33 |
Correct |
26 ms |
6892 KB |
Output is correct |
34 |
Correct |
26 ms |
6892 KB |
Output is correct |
35 |
Correct |
27 ms |
7020 KB |
Output is correct |
36 |
Correct |
27 ms |
7040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
876 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
1260 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
1260 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
4 ms |
2412 KB |
Output is correct |
11 |
Correct |
4 ms |
2412 KB |
Output is correct |
12 |
Correct |
4 ms |
2412 KB |
Output is correct |
13 |
Correct |
4 ms |
2156 KB |
Output is correct |
14 |
Correct |
5 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2284 KB |
Output is correct |
16 |
Correct |
4 ms |
2412 KB |
Output is correct |
17 |
Correct |
3 ms |
1644 KB |
Output is correct |
18 |
Correct |
4 ms |
2028 KB |
Output is correct |
19 |
Correct |
4 ms |
2156 KB |
Output is correct |
20 |
Correct |
5 ms |
2432 KB |
Output is correct |
21 |
Correct |
12 ms |
4588 KB |
Output is correct |
22 |
Correct |
20 ms |
5228 KB |
Output is correct |
23 |
Correct |
8 ms |
3692 KB |
Output is correct |
24 |
Correct |
24 ms |
6508 KB |
Output is correct |
25 |
Correct |
26 ms |
6508 KB |
Output is correct |
26 |
Correct |
27 ms |
6892 KB |
Output is correct |
27 |
Correct |
26 ms |
6892 KB |
Output is correct |
28 |
Correct |
32 ms |
7020 KB |
Output is correct |
29 |
Correct |
27 ms |
6892 KB |
Output is correct |
30 |
Correct |
26 ms |
6764 KB |
Output is correct |
31 |
Correct |
27 ms |
6892 KB |
Output is correct |
32 |
Correct |
26 ms |
6892 KB |
Output is correct |
33 |
Correct |
26 ms |
6892 KB |
Output is correct |
34 |
Correct |
26 ms |
6892 KB |
Output is correct |
35 |
Correct |
27 ms |
7020 KB |
Output is correct |
36 |
Correct |
27 ms |
7040 KB |
Output is correct |
37 |
Correct |
94 ms |
13420 KB |
Output is correct |
38 |
Correct |
94 ms |
13292 KB |
Output is correct |
39 |
Correct |
149 ms |
16492 KB |
Output is correct |
40 |
Correct |
170 ms |
17900 KB |
Output is correct |
41 |
Correct |
168 ms |
17772 KB |
Output is correct |
42 |
Correct |
149 ms |
16620 KB |
Output is correct |
43 |
Correct |
150 ms |
16492 KB |
Output is correct |
44 |
Correct |
158 ms |
16748 KB |
Output is correct |
45 |
Correct |
158 ms |
16876 KB |
Output is correct |
46 |
Correct |
162 ms |
17644 KB |
Output is correct |
47 |
Correct |
149 ms |
16620 KB |
Output is correct |
48 |
Correct |
156 ms |
16748 KB |
Output is correct |
49 |
Correct |
152 ms |
16616 KB |
Output is correct |
50 |
Correct |
147 ms |
16620 KB |
Output is correct |
51 |
Correct |
13 ms |
16236 KB |
Output is correct |
52 |
Correct |
185 ms |
18284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
876 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
1260 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
1260 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
4 ms |
2412 KB |
Output is correct |
11 |
Correct |
4 ms |
2412 KB |
Output is correct |
12 |
Correct |
4 ms |
2412 KB |
Output is correct |
13 |
Correct |
4 ms |
2156 KB |
Output is correct |
14 |
Correct |
5 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2284 KB |
Output is correct |
16 |
Correct |
4 ms |
2412 KB |
Output is correct |
17 |
Correct |
3 ms |
1644 KB |
Output is correct |
18 |
Correct |
4 ms |
2028 KB |
Output is correct |
19 |
Correct |
4 ms |
2156 KB |
Output is correct |
20 |
Correct |
5 ms |
2432 KB |
Output is correct |
21 |
Correct |
12 ms |
4588 KB |
Output is correct |
22 |
Correct |
20 ms |
5228 KB |
Output is correct |
23 |
Correct |
8 ms |
3692 KB |
Output is correct |
24 |
Correct |
24 ms |
6508 KB |
Output is correct |
25 |
Correct |
26 ms |
6508 KB |
Output is correct |
26 |
Correct |
27 ms |
6892 KB |
Output is correct |
27 |
Correct |
26 ms |
6892 KB |
Output is correct |
28 |
Correct |
32 ms |
7020 KB |
Output is correct |
29 |
Correct |
27 ms |
6892 KB |
Output is correct |
30 |
Correct |
26 ms |
6764 KB |
Output is correct |
31 |
Correct |
27 ms |
6892 KB |
Output is correct |
32 |
Correct |
26 ms |
6892 KB |
Output is correct |
33 |
Correct |
26 ms |
6892 KB |
Output is correct |
34 |
Correct |
26 ms |
6892 KB |
Output is correct |
35 |
Correct |
27 ms |
7020 KB |
Output is correct |
36 |
Correct |
27 ms |
7040 KB |
Output is correct |
37 |
Correct |
94 ms |
13420 KB |
Output is correct |
38 |
Correct |
94 ms |
13292 KB |
Output is correct |
39 |
Correct |
149 ms |
16492 KB |
Output is correct |
40 |
Correct |
170 ms |
17900 KB |
Output is correct |
41 |
Correct |
168 ms |
17772 KB |
Output is correct |
42 |
Correct |
149 ms |
16620 KB |
Output is correct |
43 |
Correct |
150 ms |
16492 KB |
Output is correct |
44 |
Correct |
158 ms |
16748 KB |
Output is correct |
45 |
Correct |
158 ms |
16876 KB |
Output is correct |
46 |
Correct |
162 ms |
17644 KB |
Output is correct |
47 |
Correct |
149 ms |
16620 KB |
Output is correct |
48 |
Correct |
156 ms |
16748 KB |
Output is correct |
49 |
Correct |
152 ms |
16616 KB |
Output is correct |
50 |
Correct |
147 ms |
16620 KB |
Output is correct |
51 |
Correct |
13 ms |
16236 KB |
Output is correct |
52 |
Correct |
185 ms |
18284 KB |
Output is correct |
53 |
Correct |
211 ms |
19872 KB |
Output is correct |
54 |
Correct |
288 ms |
23276 KB |
Output is correct |
55 |
Correct |
310 ms |
23664 KB |
Output is correct |
56 |
Correct |
222 ms |
20332 KB |
Output is correct |
57 |
Correct |
315 ms |
23684 KB |
Output is correct |
58 |
Correct |
288 ms |
23208 KB |
Output is correct |
59 |
Correct |
297 ms |
23280 KB |
Output is correct |
60 |
Correct |
18 ms |
22508 KB |
Output is correct |
61 |
Correct |
302 ms |
23408 KB |
Output is correct |
62 |
Correct |
263 ms |
21616 KB |
Output is correct |
63 |
Correct |
264 ms |
21616 KB |
Output is correct |
64 |
Correct |
252 ms |
21232 KB |
Output is correct |
65 |
Correct |
220 ms |
20716 KB |
Output is correct |
66 |
Correct |
213 ms |
20332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
876 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
1260 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
1260 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
4 ms |
2412 KB |
Output is correct |
11 |
Correct |
4 ms |
2412 KB |
Output is correct |
12 |
Correct |
4 ms |
2412 KB |
Output is correct |
13 |
Correct |
4 ms |
2156 KB |
Output is correct |
14 |
Correct |
5 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
2284 KB |
Output is correct |
16 |
Correct |
4 ms |
2412 KB |
Output is correct |
17 |
Correct |
3 ms |
1644 KB |
Output is correct |
18 |
Correct |
4 ms |
2028 KB |
Output is correct |
19 |
Correct |
4 ms |
2156 KB |
Output is correct |
20 |
Correct |
5 ms |
2432 KB |
Output is correct |
21 |
Correct |
12 ms |
4588 KB |
Output is correct |
22 |
Correct |
20 ms |
5228 KB |
Output is correct |
23 |
Correct |
8 ms |
3692 KB |
Output is correct |
24 |
Correct |
24 ms |
6508 KB |
Output is correct |
25 |
Correct |
26 ms |
6508 KB |
Output is correct |
26 |
Correct |
27 ms |
6892 KB |
Output is correct |
27 |
Correct |
26 ms |
6892 KB |
Output is correct |
28 |
Correct |
32 ms |
7020 KB |
Output is correct |
29 |
Correct |
27 ms |
6892 KB |
Output is correct |
30 |
Correct |
26 ms |
6764 KB |
Output is correct |
31 |
Correct |
27 ms |
6892 KB |
Output is correct |
32 |
Correct |
26 ms |
6892 KB |
Output is correct |
33 |
Correct |
26 ms |
6892 KB |
Output is correct |
34 |
Correct |
26 ms |
6892 KB |
Output is correct |
35 |
Correct |
27 ms |
7020 KB |
Output is correct |
36 |
Correct |
27 ms |
7040 KB |
Output is correct |
37 |
Correct |
94 ms |
13420 KB |
Output is correct |
38 |
Correct |
94 ms |
13292 KB |
Output is correct |
39 |
Correct |
149 ms |
16492 KB |
Output is correct |
40 |
Correct |
170 ms |
17900 KB |
Output is correct |
41 |
Correct |
168 ms |
17772 KB |
Output is correct |
42 |
Correct |
149 ms |
16620 KB |
Output is correct |
43 |
Correct |
150 ms |
16492 KB |
Output is correct |
44 |
Correct |
158 ms |
16748 KB |
Output is correct |
45 |
Correct |
158 ms |
16876 KB |
Output is correct |
46 |
Correct |
162 ms |
17644 KB |
Output is correct |
47 |
Correct |
149 ms |
16620 KB |
Output is correct |
48 |
Correct |
156 ms |
16748 KB |
Output is correct |
49 |
Correct |
152 ms |
16616 KB |
Output is correct |
50 |
Correct |
147 ms |
16620 KB |
Output is correct |
51 |
Correct |
13 ms |
16236 KB |
Output is correct |
52 |
Correct |
185 ms |
18284 KB |
Output is correct |
53 |
Correct |
211 ms |
19872 KB |
Output is correct |
54 |
Correct |
288 ms |
23276 KB |
Output is correct |
55 |
Correct |
310 ms |
23664 KB |
Output is correct |
56 |
Correct |
222 ms |
20332 KB |
Output is correct |
57 |
Correct |
315 ms |
23684 KB |
Output is correct |
58 |
Correct |
288 ms |
23208 KB |
Output is correct |
59 |
Correct |
297 ms |
23280 KB |
Output is correct |
60 |
Correct |
18 ms |
22508 KB |
Output is correct |
61 |
Correct |
302 ms |
23408 KB |
Output is correct |
62 |
Correct |
263 ms |
21616 KB |
Output is correct |
63 |
Correct |
264 ms |
21616 KB |
Output is correct |
64 |
Correct |
252 ms |
21232 KB |
Output is correct |
65 |
Correct |
220 ms |
20716 KB |
Output is correct |
66 |
Correct |
213 ms |
20332 KB |
Output is correct |
67 |
Correct |
376 ms |
26556 KB |
Output is correct |
68 |
Correct |
25 ms |
31980 KB |
Output is correct |
69 |
Correct |
670 ms |
34024 KB |
Output is correct |
70 |
Correct |
603 ms |
33388 KB |
Output is correct |
71 |
Correct |
606 ms |
33388 KB |
Output is correct |
72 |
Correct |
602 ms |
32620 KB |
Output is correct |
73 |
Correct |
597 ms |
32364 KB |
Output is correct |
74 |
Correct |
671 ms |
34020 KB |
Output is correct |
75 |
Correct |
639 ms |
33640 KB |
Output is correct |
76 |
Correct |
685 ms |
34152 KB |
Output is correct |
77 |
Correct |
691 ms |
34280 KB |
Output is correct |