#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxN = 2e3+10;
int dp1[mxN], dp2[mxN][mxN];
int N, A, B;
int Y[mxN];
ll msk, ans;
int fun2(int idx, int grp) {
if (grp > B)
return 0;
if (idx == N)
return (A <= grp && grp <= B);
int &ret = dp2[idx][grp];
if (~ret) return ret;
ret = 0;
ll sum = 0;
for (int i = idx; i < N; ++i) {
sum += Y[i];
if (!(sum & msk))
ret |= fun2(i+1, grp+1);
}
return ret;
}
int fun1(int idx) {
if (idx == N)
return 0;
int &ret = dp1[idx];
if (~ret) return ret;
ret = 1e9;
ll sum = 0;
for (int i = idx; i < N; ++i) {
sum += Y[i];
if (!(sum & msk))
ret = min(ret, fun1(i+1) + 1);
}
return ret;
}
bool check2() {
memset(dp2, -1, sizeof dp2);
return fun2(0, 0);
}
bool check1() {
memset(dp1, -1, sizeof dp1);
return fun1(0) <= B;
}
void solve1() {
for (int bit = 50; bit >= 0; --bit) {
msk |= (1LL << bit);
if (!check1())
msk ^= (1LL << bit), ans |= (1LL << bit);
}
cout << ans << endl;
}
void solve2() {
for (int bit = 50; bit >= 0; --bit) {
msk |= (1LL << bit);
if (!check2())
msk ^= (1LL << bit), ans |= (1LL << bit);
}
cout << ans << endl;
}
void solve() {
cin >> N >> A >> B;
for (int i = 0; i < N; ++i)
cin >> Y[i];
if (A == 1) {
solve1();
}
else {
solve2();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
104 ms |
16076 KB |
Output is correct |
15 |
Correct |
108 ms |
16076 KB |
Output is correct |
16 |
Correct |
106 ms |
16112 KB |
Output is correct |
17 |
Correct |
107 ms |
16112 KB |
Output is correct |
18 |
Correct |
107 ms |
16116 KB |
Output is correct |
19 |
Correct |
106 ms |
16108 KB |
Output is correct |
20 |
Correct |
110 ms |
16116 KB |
Output is correct |
21 |
Correct |
105 ms |
16076 KB |
Output is correct |
22 |
Correct |
105 ms |
16112 KB |
Output is correct |
23 |
Correct |
106 ms |
16108 KB |
Output is correct |
24 |
Correct |
111 ms |
16108 KB |
Output is correct |
25 |
Correct |
109 ms |
16108 KB |
Output is correct |
26 |
Correct |
107 ms |
16116 KB |
Output is correct |
27 |
Correct |
1 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
109 ms |
16076 KB |
Output is correct |
15 |
Correct |
104 ms |
16108 KB |
Output is correct |
16 |
Correct |
105 ms |
16108 KB |
Output is correct |
17 |
Correct |
108 ms |
16112 KB |
Output is correct |
18 |
Correct |
108 ms |
16076 KB |
Output is correct |
19 |
Correct |
112 ms |
16112 KB |
Output is correct |
20 |
Correct |
104 ms |
16076 KB |
Output is correct |
21 |
Correct |
104 ms |
16108 KB |
Output is correct |
22 |
Correct |
109 ms |
16108 KB |
Output is correct |
23 |
Correct |
108 ms |
16116 KB |
Output is correct |
24 |
Correct |
102 ms |
16076 KB |
Output is correct |
25 |
Correct |
106 ms |
16116 KB |
Output is correct |
26 |
Correct |
107 ms |
16196 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
2 ms |
204 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
103 ms |
16128 KB |
Output is correct |
15 |
Correct |
107 ms |
16112 KB |
Output is correct |
16 |
Correct |
103 ms |
16196 KB |
Output is correct |
17 |
Correct |
103 ms |
16112 KB |
Output is correct |
18 |
Correct |
103 ms |
16112 KB |
Output is correct |
19 |
Correct |
103 ms |
16196 KB |
Output is correct |
20 |
Correct |
107 ms |
16112 KB |
Output is correct |
21 |
Correct |
106 ms |
16116 KB |
Output is correct |
22 |
Correct |
103 ms |
16076 KB |
Output is correct |
23 |
Correct |
108 ms |
16076 KB |
Output is correct |
24 |
Correct |
106 ms |
16020 KB |
Output is correct |
25 |
Correct |
108 ms |
16076 KB |
Output is correct |
26 |
Correct |
106 ms |
16124 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
3 ms |
204 KB |
Output is correct |
50 |
Correct |
2 ms |
332 KB |
Output is correct |
51 |
Correct |
2 ms |
204 KB |
Output is correct |
52 |
Correct |
2 ms |
332 KB |
Output is correct |
53 |
Correct |
2 ms |
332 KB |
Output is correct |
54 |
Correct |
2 ms |
332 KB |
Output is correct |
55 |
Correct |
2 ms |
204 KB |
Output is correct |
56 |
Correct |
1 ms |
332 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
1 ms |
332 KB |
Output is correct |
62 |
Correct |
2 ms |
332 KB |
Output is correct |
63 |
Correct |
2 ms |
332 KB |
Output is correct |
64 |
Correct |
146 ms |
16116 KB |
Output is correct |
65 |
Correct |
106 ms |
16076 KB |
Output is correct |
66 |
Correct |
109 ms |
16116 KB |
Output is correct |
67 |
Correct |
111 ms |
16108 KB |
Output is correct |
68 |
Correct |
120 ms |
16076 KB |
Output is correct |
69 |
Correct |
126 ms |
16076 KB |
Output is correct |
70 |
Correct |
130 ms |
16116 KB |
Output is correct |
71 |
Correct |
108 ms |
16116 KB |
Output is correct |
72 |
Correct |
132 ms |
16116 KB |
Output is correct |
73 |
Correct |
127 ms |
16108 KB |
Output is correct |
74 |
Correct |
131 ms |
16112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
2 ms |
204 KB |
Output is correct |
40 |
Correct |
2 ms |
204 KB |
Output is correct |
41 |
Correct |
2 ms |
332 KB |
Output is correct |
42 |
Correct |
2 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
21 ms |
356 KB |
Output is correct |
53 |
Correct |
24 ms |
332 KB |
Output is correct |
54 |
Correct |
64 ms |
332 KB |
Output is correct |
55 |
Correct |
49 ms |
332 KB |
Output is correct |
56 |
Correct |
153 ms |
332 KB |
Output is correct |
57 |
Correct |
150 ms |
352 KB |
Output is correct |
58 |
Correct |
159 ms |
444 KB |
Output is correct |
59 |
Correct |
181 ms |
332 KB |
Output is correct |
60 |
Correct |
168 ms |
436 KB |
Output is correct |
61 |
Correct |
1 ms |
332 KB |
Output is correct |
62 |
Correct |
25 ms |
460 KB |
Output is correct |
63 |
Correct |
60 ms |
372 KB |
Output is correct |
64 |
Correct |
40 ms |
400 KB |
Output is correct |
65 |
Correct |
77 ms |
408 KB |
Output is correct |
66 |
Correct |
112 ms |
412 KB |
Output is correct |
67 |
Correct |
149 ms |
332 KB |
Output is correct |
68 |
Correct |
222 ms |
428 KB |
Output is correct |
69 |
Correct |
153 ms |
428 KB |
Output is correct |