#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e3+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,a,b,u[N],v[N][N];
bool oka(ll k){
memset(v,0,sizeof(v));
v[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=b&&j<=i;j++){
v[i][j]=0;
for(int g=1;g<=i;g++){
//cout<<i-g<<"\n";
if(((u[i]-u[i-g])|k)<=k&&v[i-g][j-1]==1)v[i][j]=1;
}
}
}
for(int i=a;i<=b;i++)if(v[n][i])return 1;
return 0;
}
bool okb(ll k){
ll f[N];
f[0]=0;
for(int i=1;i<=n;i++){
f[i]=INF;
for(int j=1;j<=i;j++){
if(((u[i]-u[i-j])|k)<=k)f[i]=min(f[i],f[i-j]+1);
}
}
return (f[n]<=b);
}
void solvea(){
ll bit=(1LL<<41)-1;
for(int i=40;i>=0;i--){
if(oka(bit^(1LL<<i)))bit^=(1LL<<i);
}
cout<<bit<<"\n";
}
void solveb(){
ll bit=(1LL<<41)-1;
for(int i=40;i>=0;i--){
if(okb(bit^(1LL<<i)))bit^=(1LL<<i);
}
cout<<bit<<"\n";
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>a>>b;
REP1(i,n)cin>>u[i],u[i]+=u[i-1];
if(a==1){
solveb();
}else{
solvea();
}
return 0;
}
/*
6 2 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
183 ms |
31852 KB |
Output is correct |
15 |
Correct |
175 ms |
31872 KB |
Output is correct |
16 |
Correct |
176 ms |
31980 KB |
Output is correct |
17 |
Correct |
190 ms |
31980 KB |
Output is correct |
18 |
Correct |
183 ms |
31852 KB |
Output is correct |
19 |
Correct |
183 ms |
31852 KB |
Output is correct |
20 |
Correct |
213 ms |
31852 KB |
Output is correct |
21 |
Correct |
176 ms |
31980 KB |
Output is correct |
22 |
Correct |
177 ms |
31980 KB |
Output is correct |
23 |
Correct |
182 ms |
31980 KB |
Output is correct |
24 |
Correct |
176 ms |
31980 KB |
Output is correct |
25 |
Correct |
178 ms |
31852 KB |
Output is correct |
26 |
Correct |
190 ms |
31980 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
175 ms |
31980 KB |
Output is correct |
15 |
Correct |
183 ms |
31980 KB |
Output is correct |
16 |
Correct |
178 ms |
31980 KB |
Output is correct |
17 |
Correct |
174 ms |
31852 KB |
Output is correct |
18 |
Correct |
183 ms |
31872 KB |
Output is correct |
19 |
Correct |
175 ms |
31852 KB |
Output is correct |
20 |
Correct |
175 ms |
31852 KB |
Output is correct |
21 |
Correct |
176 ms |
31852 KB |
Output is correct |
22 |
Correct |
175 ms |
31852 KB |
Output is correct |
23 |
Correct |
184 ms |
31852 KB |
Output is correct |
24 |
Correct |
177 ms |
31980 KB |
Output is correct |
25 |
Correct |
182 ms |
31852 KB |
Output is correct |
26 |
Correct |
186 ms |
31872 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
177 ms |
31852 KB |
Output is correct |
15 |
Correct |
177 ms |
31980 KB |
Output is correct |
16 |
Correct |
181 ms |
31980 KB |
Output is correct |
17 |
Correct |
183 ms |
31980 KB |
Output is correct |
18 |
Correct |
182 ms |
31852 KB |
Output is correct |
19 |
Correct |
222 ms |
31852 KB |
Output is correct |
20 |
Correct |
177 ms |
31852 KB |
Output is correct |
21 |
Correct |
184 ms |
31852 KB |
Output is correct |
22 |
Correct |
185 ms |
31980 KB |
Output is correct |
23 |
Correct |
180 ms |
31852 KB |
Output is correct |
24 |
Correct |
177 ms |
31980 KB |
Output is correct |
25 |
Correct |
182 ms |
31980 KB |
Output is correct |
26 |
Correct |
181 ms |
31852 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
1 ms |
364 KB |
Output is correct |
45 |
Correct |
1 ms |
364 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
1 ms |
364 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
1 ms |
384 KB |
Output is correct |
52 |
Correct |
1 ms |
364 KB |
Output is correct |
53 |
Correct |
4 ms |
364 KB |
Output is correct |
54 |
Correct |
1 ms |
364 KB |
Output is correct |
55 |
Correct |
1 ms |
364 KB |
Output is correct |
56 |
Correct |
1 ms |
364 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
195 ms |
31872 KB |
Output is correct |
65 |
Correct |
181 ms |
31852 KB |
Output is correct |
66 |
Correct |
177 ms |
31852 KB |
Output is correct |
67 |
Correct |
181 ms |
31852 KB |
Output is correct |
68 |
Correct |
187 ms |
31852 KB |
Output is correct |
69 |
Correct |
190 ms |
31980 KB |
Output is correct |
70 |
Correct |
193 ms |
31980 KB |
Output is correct |
71 |
Correct |
183 ms |
31852 KB |
Output is correct |
72 |
Correct |
201 ms |
31980 KB |
Output is correct |
73 |
Correct |
196 ms |
31980 KB |
Output is correct |
74 |
Correct |
189 ms |
31980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
404 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
2 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
1 ms |
384 KB |
Output is correct |
45 |
Correct |
1 ms |
364 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
1 ms |
364 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
10 ms |
364 KB |
Output is correct |
53 |
Correct |
16 ms |
492 KB |
Output is correct |
54 |
Correct |
29 ms |
364 KB |
Output is correct |
55 |
Correct |
32 ms |
364 KB |
Output is correct |
56 |
Correct |
103 ms |
364 KB |
Output is correct |
57 |
Correct |
98 ms |
364 KB |
Output is correct |
58 |
Correct |
89 ms |
364 KB |
Output is correct |
59 |
Correct |
90 ms |
364 KB |
Output is correct |
60 |
Correct |
99 ms |
452 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
15 ms |
364 KB |
Output is correct |
63 |
Correct |
28 ms |
364 KB |
Output is correct |
64 |
Correct |
29 ms |
364 KB |
Output is correct |
65 |
Correct |
48 ms |
444 KB |
Output is correct |
66 |
Correct |
79 ms |
364 KB |
Output is correct |
67 |
Correct |
98 ms |
364 KB |
Output is correct |
68 |
Correct |
101 ms |
492 KB |
Output is correct |
69 |
Correct |
110 ms |
512 KB |
Output is correct |