#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=2000;
const ll mod=1e9+7;
const ll inf=1e9+500;
ll a[maxn];
ll n,A,B;
ll dpa1[maxn];
bool shoda1(ll res){
dpa1[0]=0;
for(ll i=1;i<=n;i++){
dpa1[i]=inf;
ll sum=0;
for(ll j=i;j>=1;j--){
sum+=a[j];
if((sum|res)==res){
dpa1[i]=min(dpa1[i],dpa1[j-1]+1);
}
}
}
if(dpa1[n]<=B){
return 1;
}
return 0;
}
bool dp[maxn][maxn];
bool shod(ll res){
dp[0][0]=1;
for(ll i=1;i<=n;i++){
for(ll z=1;z<=n;z++){
ll sum=0;
for(ll j=i;j>=1;j--){
sum+=a[j];
if((sum|res)==res){
dp[i][z]|=dp[j-1][z-1];
}
}
}
}
for(ll i=A;i<=B;i++){
if(dp[n][i]){
return 1;
}
}
return 0;
}
int main(){
cin>>n>>A>>B;
for(ll i=1;i<=n;i++){
cin>>a[i];
}
if(A==1){
ll res=0;
for(ll i=60;i>=0;i--){
if(!shoda1(res+(1LL<<i)-1)){
res+=(1LL<<i);
}
}
cout<<res<<endl;
}
else{
ll res=0;
for(ll i=60;i>=0;i--){
if(!shod(res+(1LL<<i)-1)){
res+=(1LL<<i);
}
}
cout<<res<<endl;
}
}
/*
. _______ __ ___ ________ ________ _________ _________ ________
. / \ | | / / / \ | \ / \ | | | __ \
. / _____/ | | / / / ___ \ | ___ \ | _______/ | ______| | | \ \
. / / | |/ / / / \ \ | | \ \ | (______ | |_____ | |__/ /
. | | | / | / \ | | | | | \ \ | | | __/
. | | | \ | \ / | | | | | \______ \ | ______| | \
. \ \_____ | |\ \ \ \___/ / | |___/ / _______) | | |_____ | |\ \
. \ \ | | \ \ \ / | / / / | | | | \ \
. \_______/ |__| \__\ \________/ |________/ \________/ |________| |___| \__\
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
452 KB |
Output is correct |
7 |
Correct |
2 ms |
456 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
544 KB |
Output is correct |
10 |
Correct |
2 ms |
676 KB |
Output is correct |
11 |
Correct |
2 ms |
676 KB |
Output is correct |
12 |
Correct |
2 ms |
676 KB |
Output is correct |
13 |
Correct |
2 ms |
676 KB |
Output is correct |
14 |
Incorrect |
2 ms |
676 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
676 KB |
Output is correct |
2 |
Correct |
2 ms |
676 KB |
Output is correct |
3 |
Correct |
2 ms |
676 KB |
Output is correct |
4 |
Correct |
2 ms |
816 KB |
Output is correct |
5 |
Correct |
2 ms |
816 KB |
Output is correct |
6 |
Correct |
2 ms |
816 KB |
Output is correct |
7 |
Correct |
2 ms |
816 KB |
Output is correct |
8 |
Correct |
2 ms |
816 KB |
Output is correct |
9 |
Correct |
2 ms |
816 KB |
Output is correct |
10 |
Correct |
2 ms |
816 KB |
Output is correct |
11 |
Correct |
2 ms |
816 KB |
Output is correct |
12 |
Correct |
2 ms |
816 KB |
Output is correct |
13 |
Correct |
2 ms |
892 KB |
Output is correct |
14 |
Incorrect |
2 ms |
900 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
900 KB |
Output is correct |
2 |
Correct |
2 ms |
900 KB |
Output is correct |
3 |
Correct |
2 ms |
900 KB |
Output is correct |
4 |
Correct |
2 ms |
900 KB |
Output is correct |
5 |
Correct |
2 ms |
900 KB |
Output is correct |
6 |
Correct |
2 ms |
900 KB |
Output is correct |
7 |
Correct |
2 ms |
900 KB |
Output is correct |
8 |
Correct |
2 ms |
900 KB |
Output is correct |
9 |
Correct |
2 ms |
900 KB |
Output is correct |
10 |
Correct |
2 ms |
900 KB |
Output is correct |
11 |
Correct |
2 ms |
996 KB |
Output is correct |
12 |
Correct |
2 ms |
1000 KB |
Output is correct |
13 |
Correct |
2 ms |
1000 KB |
Output is correct |
14 |
Correct |
2 ms |
1000 KB |
Output is correct |
15 |
Correct |
2 ms |
1000 KB |
Output is correct |
16 |
Correct |
2 ms |
1000 KB |
Output is correct |
17 |
Correct |
2 ms |
1000 KB |
Output is correct |
18 |
Correct |
2 ms |
1000 KB |
Output is correct |
19 |
Correct |
2 ms |
1000 KB |
Output is correct |
20 |
Correct |
2 ms |
1036 KB |
Output is correct |
21 |
Correct |
2 ms |
1036 KB |
Output is correct |
22 |
Correct |
2 ms |
1036 KB |
Output is correct |
23 |
Correct |
2 ms |
1036 KB |
Output is correct |
24 |
Correct |
2 ms |
1036 KB |
Output is correct |
25 |
Correct |
2 ms |
1036 KB |
Output is correct |
26 |
Correct |
2 ms |
1036 KB |
Output is correct |
27 |
Correct |
3 ms |
1036 KB |
Output is correct |
28 |
Correct |
3 ms |
1036 KB |
Output is correct |
29 |
Correct |
3 ms |
1036 KB |
Output is correct |
30 |
Correct |
3 ms |
1036 KB |
Output is correct |
31 |
Correct |
3 ms |
1036 KB |
Output is correct |
32 |
Correct |
3 ms |
1036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1036 KB |
Output is correct |
2 |
Correct |
2 ms |
1036 KB |
Output is correct |
3 |
Correct |
2 ms |
1036 KB |
Output is correct |
4 |
Correct |
2 ms |
1036 KB |
Output is correct |
5 |
Correct |
2 ms |
1036 KB |
Output is correct |
6 |
Correct |
2 ms |
1036 KB |
Output is correct |
7 |
Correct |
2 ms |
1036 KB |
Output is correct |
8 |
Correct |
2 ms |
1132 KB |
Output is correct |
9 |
Correct |
2 ms |
1140 KB |
Output is correct |
10 |
Correct |
2 ms |
1140 KB |
Output is correct |
11 |
Correct |
2 ms |
1140 KB |
Output is correct |
12 |
Correct |
2 ms |
1140 KB |
Output is correct |
13 |
Correct |
2 ms |
1140 KB |
Output is correct |
14 |
Incorrect |
2 ms |
1140 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1140 KB |
Output is correct |
2 |
Correct |
2 ms |
1140 KB |
Output is correct |
3 |
Correct |
2 ms |
1140 KB |
Output is correct |
4 |
Correct |
2 ms |
1140 KB |
Output is correct |
5 |
Correct |
2 ms |
1140 KB |
Output is correct |
6 |
Correct |
2 ms |
1196 KB |
Output is correct |
7 |
Correct |
2 ms |
1200 KB |
Output is correct |
8 |
Correct |
2 ms |
1200 KB |
Output is correct |
9 |
Correct |
2 ms |
1200 KB |
Output is correct |
10 |
Correct |
2 ms |
1220 KB |
Output is correct |
11 |
Correct |
2 ms |
1224 KB |
Output is correct |
12 |
Correct |
2 ms |
1224 KB |
Output is correct |
13 |
Correct |
2 ms |
1224 KB |
Output is correct |
14 |
Correct |
2 ms |
1224 KB |
Output is correct |
15 |
Correct |
2 ms |
1224 KB |
Output is correct |
16 |
Correct |
2 ms |
1224 KB |
Output is correct |
17 |
Correct |
2 ms |
1224 KB |
Output is correct |
18 |
Correct |
2 ms |
1224 KB |
Output is correct |
19 |
Correct |
2 ms |
1224 KB |
Output is correct |
20 |
Correct |
2 ms |
1224 KB |
Output is correct |
21 |
Correct |
2 ms |
1224 KB |
Output is correct |
22 |
Correct |
2 ms |
1224 KB |
Output is correct |
23 |
Correct |
2 ms |
1272 KB |
Output is correct |
24 |
Correct |
2 ms |
1272 KB |
Output is correct |
25 |
Correct |
2 ms |
1272 KB |
Output is correct |
26 |
Correct |
2 ms |
1272 KB |
Output is correct |
27 |
Correct |
3 ms |
1272 KB |
Output is correct |
28 |
Correct |
2 ms |
1272 KB |
Output is correct |
29 |
Correct |
2 ms |
1272 KB |
Output is correct |
30 |
Correct |
2 ms |
1272 KB |
Output is correct |
31 |
Correct |
2 ms |
1312 KB |
Output is correct |
32 |
Correct |
2 ms |
1312 KB |
Output is correct |
33 |
Correct |
2 ms |
1312 KB |
Output is correct |
34 |
Correct |
2 ms |
1312 KB |
Output is correct |
35 |
Correct |
2 ms |
1312 KB |
Output is correct |
36 |
Correct |
3 ms |
1312 KB |
Output is correct |
37 |
Correct |
3 ms |
1312 KB |
Output is correct |
38 |
Correct |
3 ms |
1312 KB |
Output is correct |
39 |
Correct |
3 ms |
1312 KB |
Output is correct |
40 |
Correct |
3 ms |
1312 KB |
Output is correct |
41 |
Correct |
3 ms |
1312 KB |
Output is correct |
42 |
Correct |
3 ms |
1312 KB |
Output is correct |
43 |
Correct |
2 ms |
1312 KB |
Output is correct |
44 |
Correct |
3 ms |
1312 KB |
Output is correct |
45 |
Correct |
3 ms |
1312 KB |
Output is correct |
46 |
Correct |
3 ms |
1312 KB |
Output is correct |
47 |
Correct |
3 ms |
1416 KB |
Output is correct |
48 |
Correct |
3 ms |
1416 KB |
Output is correct |
49 |
Correct |
3 ms |
1416 KB |
Output is correct |
50 |
Correct |
3 ms |
1416 KB |
Output is correct |
51 |
Correct |
3 ms |
1416 KB |
Output is correct |
52 |
Correct |
27 ms |
1416 KB |
Output is correct |
53 |
Correct |
33 ms |
1416 KB |
Output is correct |
54 |
Correct |
63 ms |
1416 KB |
Output is correct |
55 |
Correct |
63 ms |
1416 KB |
Output is correct |
56 |
Incorrect |
222 ms |
1440 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |