#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx = 2005;
int n, A, B;
ll S[mx], ans;
bool dp1[105][105];
void solve1(){
ans = 0;
ll cur = 0;
for(int b = 41; b >= 0; b--){
ll t = cur | (1LL << b);
dp1[0][0] = true;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++){
dp1[i][j] = false;
for(int k = 0; k < i; k++){
ll ps = S[i] - S[k];
if(!(ps & t)){
dp1[i][j] |= dp1[k][j-1];
}
}
}
}
bool able = false;
for(int i = A; i <= B; i++){
able |= dp1[n][i];
}
if(able){
cur = t;
}else{
ans |= (1LL << b);
}
}
}
int dp2[mx];
void solve2(){
ans = 0;
ll cur = 0;
for(int b = 41; b >= 0; b--){
ll t = cur | (1LL << b);
for(int i = 1; i <= n; i++){
dp2[i] = 1e9;
for(int j = 0; j < i; j++){
ll ps = S[i] - S[j];
if(!(ps & t)){
dp2[i] = min(dp2[i], dp2[j] + 1);
}
}
}
if(dp2[n] <= B){
cur = t;
}else{
ans |= (1LL << b);
}
}
}
void input(){
cin >> n >> A >> B;
for(int i = 1; i <= n; i++){
cin >> S[i];
S[i] += S[i-1];
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
input();
n <= 100 ? solve1() : solve2();
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
532 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
548 KB |
Output is correct |
9 |
Correct |
2 ms |
548 KB |
Output is correct |
10 |
Correct |
2 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
2 ms |
548 KB |
Output is correct |
13 |
Correct |
2 ms |
548 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
716 KB |
Output is correct |
20 |
Correct |
2 ms |
716 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
2 ms |
716 KB |
Output is correct |
27 |
Correct |
1 ms |
716 KB |
Output is correct |
28 |
Correct |
1 ms |
716 KB |
Output is correct |
29 |
Correct |
1 ms |
716 KB |
Output is correct |
30 |
Correct |
2 ms |
716 KB |
Output is correct |
31 |
Correct |
2 ms |
716 KB |
Output is correct |
32 |
Correct |
2 ms |
716 KB |
Output is correct |
33 |
Correct |
2 ms |
716 KB |
Output is correct |
34 |
Correct |
2 ms |
728 KB |
Output is correct |
35 |
Correct |
2 ms |
728 KB |
Output is correct |
36 |
Correct |
2 ms |
728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
728 KB |
Output is correct |
2 |
Correct |
2 ms |
728 KB |
Output is correct |
3 |
Correct |
1 ms |
728 KB |
Output is correct |
4 |
Correct |
1 ms |
728 KB |
Output is correct |
5 |
Correct |
2 ms |
728 KB |
Output is correct |
6 |
Correct |
2 ms |
728 KB |
Output is correct |
7 |
Correct |
2 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
2 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
728 KB |
Output is correct |
12 |
Correct |
2 ms |
728 KB |
Output is correct |
13 |
Correct |
2 ms |
728 KB |
Output is correct |
14 |
Correct |
1 ms |
728 KB |
Output is correct |
15 |
Correct |
1 ms |
728 KB |
Output is correct |
16 |
Correct |
2 ms |
728 KB |
Output is correct |
17 |
Correct |
2 ms |
728 KB |
Output is correct |
18 |
Correct |
1 ms |
728 KB |
Output is correct |
19 |
Correct |
2 ms |
728 KB |
Output is correct |
20 |
Correct |
2 ms |
728 KB |
Output is correct |
21 |
Correct |
2 ms |
728 KB |
Output is correct |
22 |
Correct |
2 ms |
728 KB |
Output is correct |
23 |
Correct |
2 ms |
728 KB |
Output is correct |
24 |
Correct |
2 ms |
728 KB |
Output is correct |
25 |
Correct |
2 ms |
728 KB |
Output is correct |
26 |
Correct |
2 ms |
728 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
728 KB |
Output is correct |
29 |
Correct |
4 ms |
728 KB |
Output is correct |
30 |
Correct |
4 ms |
728 KB |
Output is correct |
31 |
Correct |
6 ms |
728 KB |
Output is correct |
32 |
Correct |
5 ms |
748 KB |
Output is correct |
33 |
Correct |
7 ms |
748 KB |
Output is correct |
34 |
Correct |
5 ms |
748 KB |
Output is correct |
35 |
Correct |
6 ms |
748 KB |
Output is correct |
36 |
Correct |
5 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
748 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
4 |
Correct |
2 ms |
748 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
2 ms |
748 KB |
Output is correct |
7 |
Correct |
2 ms |
748 KB |
Output is correct |
8 |
Correct |
2 ms |
748 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
748 KB |
Output is correct |
16 |
Correct |
3 ms |
748 KB |
Output is correct |
17 |
Correct |
4 ms |
748 KB |
Output is correct |
18 |
Correct |
5 ms |
748 KB |
Output is correct |
19 |
Correct |
5 ms |
748 KB |
Output is correct |
20 |
Correct |
6 ms |
748 KB |
Output is correct |
21 |
Correct |
5 ms |
748 KB |
Output is correct |
22 |
Correct |
5 ms |
748 KB |
Output is correct |
23 |
Correct |
5 ms |
748 KB |
Output is correct |
24 |
Correct |
6 ms |
748 KB |
Output is correct |
25 |
Correct |
10 ms |
748 KB |
Output is correct |
26 |
Correct |
17 ms |
748 KB |
Output is correct |
27 |
Correct |
25 ms |
748 KB |
Output is correct |
28 |
Correct |
33 ms |
748 KB |
Output is correct |
29 |
Correct |
32 ms |
748 KB |
Output is correct |
30 |
Correct |
34 ms |
748 KB |
Output is correct |
31 |
Correct |
34 ms |
748 KB |
Output is correct |
32 |
Correct |
34 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
4 |
Correct |
2 ms |
748 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
2 ms |
748 KB |
Output is correct |
7 |
Correct |
2 ms |
748 KB |
Output is correct |
8 |
Correct |
2 ms |
748 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
1 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
17 |
Correct |
1 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
748 KB |
Output is correct |
21 |
Correct |
2 ms |
748 KB |
Output is correct |
22 |
Correct |
2 ms |
748 KB |
Output is correct |
23 |
Correct |
2 ms |
748 KB |
Output is correct |
24 |
Correct |
2 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
748 KB |
Output is correct |
26 |
Correct |
2 ms |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
2 ms |
748 KB |
Output is correct |
29 |
Correct |
2 ms |
748 KB |
Output is correct |
30 |
Correct |
2 ms |
748 KB |
Output is correct |
31 |
Correct |
2 ms |
748 KB |
Output is correct |
32 |
Correct |
2 ms |
748 KB |
Output is correct |
33 |
Correct |
2 ms |
748 KB |
Output is correct |
34 |
Correct |
2 ms |
748 KB |
Output is correct |
35 |
Correct |
2 ms |
748 KB |
Output is correct |
36 |
Correct |
2 ms |
748 KB |
Output is correct |
37 |
Correct |
2 ms |
748 KB |
Output is correct |
38 |
Correct |
2 ms |
748 KB |
Output is correct |
39 |
Correct |
3 ms |
748 KB |
Output is correct |
40 |
Correct |
4 ms |
748 KB |
Output is correct |
41 |
Correct |
5 ms |
748 KB |
Output is correct |
42 |
Correct |
6 ms |
748 KB |
Output is correct |
43 |
Correct |
7 ms |
748 KB |
Output is correct |
44 |
Correct |
6 ms |
748 KB |
Output is correct |
45 |
Correct |
5 ms |
748 KB |
Output is correct |
46 |
Correct |
6 ms |
748 KB |
Output is correct |
47 |
Correct |
6 ms |
748 KB |
Output is correct |
48 |
Correct |
11 ms |
748 KB |
Output is correct |
49 |
Correct |
18 ms |
748 KB |
Output is correct |
50 |
Correct |
27 ms |
748 KB |
Output is correct |
51 |
Correct |
33 ms |
748 KB |
Output is correct |
52 |
Correct |
32 ms |
748 KB |
Output is correct |
53 |
Correct |
35 ms |
748 KB |
Output is correct |
54 |
Correct |
34 ms |
748 KB |
Output is correct |
55 |
Correct |
34 ms |
748 KB |
Output is correct |
56 |
Correct |
4 ms |
752 KB |
Output is correct |
57 |
Correct |
12 ms |
752 KB |
Output is correct |
58 |
Correct |
17 ms |
752 KB |
Output is correct |
59 |
Correct |
21 ms |
752 KB |
Output is correct |
60 |
Correct |
20 ms |
752 KB |
Output is correct |
61 |
Correct |
22 ms |
752 KB |
Output is correct |
62 |
Correct |
22 ms |
752 KB |
Output is correct |
63 |
Correct |
22 ms |
752 KB |
Output is correct |
64 |
Correct |
26 ms |
752 KB |
Output is correct |
65 |
Correct |
4 ms |
752 KB |
Output is correct |
66 |
Correct |
8 ms |
752 KB |
Output is correct |
67 |
Correct |
11 ms |
752 KB |
Output is correct |
68 |
Correct |
16 ms |
752 KB |
Output is correct |
69 |
Correct |
23 ms |
752 KB |
Output is correct |
70 |
Correct |
20 ms |
844 KB |
Output is correct |
71 |
Correct |
21 ms |
844 KB |
Output is correct |
72 |
Correct |
22 ms |
844 KB |
Output is correct |
73 |
Correct |
22 ms |
844 KB |
Output is correct |
74 |
Correct |
22 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
844 KB |
Output is correct |
2 |
Correct |
2 ms |
844 KB |
Output is correct |
3 |
Correct |
2 ms |
844 KB |
Output is correct |
4 |
Correct |
2 ms |
844 KB |
Output is correct |
5 |
Correct |
2 ms |
844 KB |
Output is correct |
6 |
Correct |
2 ms |
844 KB |
Output is correct |
7 |
Correct |
2 ms |
844 KB |
Output is correct |
8 |
Correct |
2 ms |
844 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
844 KB |
Output is correct |
11 |
Correct |
2 ms |
844 KB |
Output is correct |
12 |
Correct |
2 ms |
844 KB |
Output is correct |
13 |
Correct |
2 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
844 KB |
Output is correct |
15 |
Correct |
2 ms |
844 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
2 ms |
844 KB |
Output is correct |
18 |
Correct |
2 ms |
844 KB |
Output is correct |
19 |
Correct |
2 ms |
844 KB |
Output is correct |
20 |
Correct |
2 ms |
844 KB |
Output is correct |
21 |
Correct |
2 ms |
844 KB |
Output is correct |
22 |
Correct |
2 ms |
844 KB |
Output is correct |
23 |
Correct |
2 ms |
844 KB |
Output is correct |
24 |
Correct |
2 ms |
844 KB |
Output is correct |
25 |
Correct |
2 ms |
844 KB |
Output is correct |
26 |
Correct |
3 ms |
844 KB |
Output is correct |
27 |
Correct |
4 ms |
844 KB |
Output is correct |
28 |
Correct |
6 ms |
844 KB |
Output is correct |
29 |
Correct |
5 ms |
844 KB |
Output is correct |
30 |
Correct |
5 ms |
844 KB |
Output is correct |
31 |
Correct |
5 ms |
844 KB |
Output is correct |
32 |
Correct |
6 ms |
844 KB |
Output is correct |
33 |
Correct |
6 ms |
844 KB |
Output is correct |
34 |
Correct |
6 ms |
844 KB |
Output is correct |
35 |
Correct |
10 ms |
844 KB |
Output is correct |
36 |
Correct |
17 ms |
844 KB |
Output is correct |
37 |
Correct |
26 ms |
844 KB |
Output is correct |
38 |
Correct |
35 ms |
844 KB |
Output is correct |
39 |
Correct |
32 ms |
844 KB |
Output is correct |
40 |
Correct |
32 ms |
844 KB |
Output is correct |
41 |
Correct |
33 ms |
844 KB |
Output is correct |
42 |
Correct |
34 ms |
844 KB |
Output is correct |
43 |
Correct |
4 ms |
844 KB |
Output is correct |
44 |
Correct |
11 ms |
844 KB |
Output is correct |
45 |
Correct |
16 ms |
844 KB |
Output is correct |
46 |
Correct |
20 ms |
844 KB |
Output is correct |
47 |
Correct |
22 ms |
844 KB |
Output is correct |
48 |
Correct |
20 ms |
844 KB |
Output is correct |
49 |
Correct |
22 ms |
844 KB |
Output is correct |
50 |
Correct |
22 ms |
844 KB |
Output is correct |
51 |
Correct |
2 ms |
844 KB |
Output is correct |
52 |
Correct |
11 ms |
844 KB |
Output is correct |
53 |
Correct |
16 ms |
844 KB |
Output is correct |
54 |
Correct |
28 ms |
844 KB |
Output is correct |
55 |
Correct |
27 ms |
844 KB |
Output is correct |
56 |
Correct |
98 ms |
844 KB |
Output is correct |
57 |
Correct |
94 ms |
844 KB |
Output is correct |
58 |
Correct |
93 ms |
844 KB |
Output is correct |
59 |
Correct |
90 ms |
844 KB |
Output is correct |
60 |
Correct |
99 ms |
844 KB |
Output is correct |
61 |
Correct |
2 ms |
844 KB |
Output is correct |
62 |
Correct |
17 ms |
844 KB |
Output is correct |
63 |
Correct |
29 ms |
844 KB |
Output is correct |
64 |
Correct |
27 ms |
844 KB |
Output is correct |
65 |
Correct |
52 ms |
844 KB |
Output is correct |
66 |
Correct |
72 ms |
844 KB |
Output is correct |
67 |
Correct |
96 ms |
844 KB |
Output is correct |
68 |
Correct |
100 ms |
864 KB |
Output is correct |
69 |
Correct |
95 ms |
864 KB |
Output is correct |