#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define vec vector
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define fast_iati ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template <class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template <class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N=2e3+2;
const int lg=61;
const ll inf=1e18;
int dp1[N],n,a,b;
bitset<N> dp[N];
bitset<N> go[N];
ll pref[N];
ll get(int l,int r){
return pref[r]-(l?pref[l-1]:0);
}
vec<pii> e;
bool check(){
if(n>500){
for(int i=0;i<=n;i++) dp1[i]=1e9;
dp1[0]=0;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
if(go[i][j])
umin(dp1[i+1],dp1[j]+1);
}
}
return (dp1[n]<=b);
}
else{
for(int i=0;i<=n;i++){
dp[i].reset();
}
dp[0][0]=1;
for(int i=0;i<n;i++){
for(int cnt=n;cnt>=0;cnt--){
int is=(dp[cnt]&go[i]).count();
if(is)
dp[cnt+1][i+1]=1;
}
}
int ok=0;
for(int i=a;i<=b;i++)
ok|=(dp[i][n]==1);
return ok;
}
}
ll rec(int b,ll x){
for(int i=0;i<n;i++){
go[i].reset();
for(int j=0;j<=i;j++){
ll w=get(j,i);
w>>=(b);w<<=(b);
if((w|x)==x)
go[i][j]=1;
}
}
if(!check()) return -inf;
if(b==0) return x;
// cout<<"OK "<<b<<' '<<x<<endl;
// for(auto &z : e)
// cout<<z.f<<' '<<z.s<<endl;
if(b==0) return x;
ll w=rec(b-1,x);
if(w!=-inf) return w;
return rec(b-1,x+pw(b-1));
}
signed main(){
fast_iati;
cin>>n>>a>>b;
for(int i=0;i<n;i++){
cin>>pref[i];
if(i)
pref[i]+=pref[i-1];
}
cout<<rec(lg,0);
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
6 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
3 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 |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
332 KB |
Output is correct |
21 |
Correct |
6 ms |
332 KB |
Output is correct |
22 |
Correct |
4 ms |
332 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
4 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
332 KB |
Output is correct |
26 |
Correct |
3 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
3 ms |
204 KB |
Output is correct |
29 |
Correct |
3 ms |
332 KB |
Output is correct |
30 |
Correct |
4 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
4 ms |
332 KB |
Output is correct |
33 |
Correct |
4 ms |
332 KB |
Output is correct |
34 |
Correct |
4 ms |
332 KB |
Output is correct |
35 |
Correct |
5 ms |
332 KB |
Output is correct |
36 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
264 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
4 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 |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
332 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
4 ms |
332 KB |
Output is correct |
23 |
Correct |
6 ms |
204 KB |
Output is correct |
24 |
Correct |
4 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
332 KB |
Output is correct |
26 |
Correct |
3 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
332 KB |
Output is correct |
28 |
Correct |
5 ms |
332 KB |
Output is correct |
29 |
Correct |
12 ms |
352 KB |
Output is correct |
30 |
Correct |
20 ms |
348 KB |
Output is correct |
31 |
Correct |
23 ms |
356 KB |
Output is correct |
32 |
Correct |
22 ms |
344 KB |
Output is correct |
33 |
Correct |
20 ms |
352 KB |
Output is correct |
34 |
Correct |
20 ms |
352 KB |
Output is correct |
35 |
Correct |
19 ms |
352 KB |
Output is correct |
36 |
Correct |
20 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
3 ms |
332 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
11 ms |
344 KB |
Output is correct |
17 |
Correct |
14 ms |
352 KB |
Output is correct |
18 |
Correct |
22 ms |
348 KB |
Output is correct |
19 |
Correct |
20 ms |
352 KB |
Output is correct |
20 |
Correct |
27 ms |
352 KB |
Output is correct |
21 |
Correct |
19 ms |
332 KB |
Output is correct |
22 |
Correct |
20 ms |
332 KB |
Output is correct |
23 |
Correct |
19 ms |
332 KB |
Output is correct |
24 |
Correct |
20 ms |
332 KB |
Output is correct |
25 |
Correct |
33 ms |
332 KB |
Output is correct |
26 |
Correct |
47 ms |
332 KB |
Output is correct |
27 |
Correct |
64 ms |
332 KB |
Output is correct |
28 |
Correct |
79 ms |
332 KB |
Output is correct |
29 |
Correct |
74 ms |
332 KB |
Output is correct |
30 |
Correct |
81 ms |
356 KB |
Output is correct |
31 |
Correct |
77 ms |
332 KB |
Output is correct |
32 |
Correct |
75 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
328 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
3 ms |
332 KB |
Output is correct |
13 |
Correct |
6 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 |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
332 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
5 ms |
336 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
336 KB |
Output is correct |
26 |
Correct |
4 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
4 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
4 ms |
332 KB |
Output is correct |
33 |
Correct |
4 ms |
332 KB |
Output is correct |
34 |
Correct |
4 ms |
332 KB |
Output is correct |
35 |
Correct |
5 ms |
332 KB |
Output is correct |
36 |
Correct |
4 ms |
336 KB |
Output is correct |
37 |
Correct |
4 ms |
332 KB |
Output is correct |
38 |
Correct |
5 ms |
332 KB |
Output is correct |
39 |
Correct |
12 ms |
344 KB |
Output is correct |
40 |
Correct |
14 ms |
352 KB |
Output is correct |
41 |
Correct |
22 ms |
352 KB |
Output is correct |
42 |
Correct |
19 ms |
352 KB |
Output is correct |
43 |
Correct |
20 ms |
352 KB |
Output is correct |
44 |
Correct |
21 ms |
332 KB |
Output is correct |
45 |
Correct |
22 ms |
332 KB |
Output is correct |
46 |
Correct |
20 ms |
332 KB |
Output is correct |
47 |
Correct |
21 ms |
356 KB |
Output is correct |
48 |
Correct |
33 ms |
332 KB |
Output is correct |
49 |
Correct |
47 ms |
332 KB |
Output is correct |
50 |
Correct |
67 ms |
332 KB |
Output is correct |
51 |
Correct |
76 ms |
332 KB |
Output is correct |
52 |
Correct |
72 ms |
332 KB |
Output is correct |
53 |
Correct |
87 ms |
452 KB |
Output is correct |
54 |
Correct |
89 ms |
356 KB |
Output is correct |
55 |
Correct |
83 ms |
356 KB |
Output is correct |
56 |
Correct |
31 ms |
332 KB |
Output is correct |
57 |
Correct |
65 ms |
348 KB |
Output is correct |
58 |
Correct |
85 ms |
356 KB |
Output is correct |
59 |
Correct |
108 ms |
368 KB |
Output is correct |
60 |
Correct |
87 ms |
356 KB |
Output is correct |
61 |
Correct |
86 ms |
356 KB |
Output is correct |
62 |
Correct |
103 ms |
360 KB |
Output is correct |
63 |
Correct |
109 ms |
332 KB |
Output is correct |
64 |
Correct |
58 ms |
352 KB |
Output is correct |
65 |
Correct |
27 ms |
460 KB |
Output is correct |
66 |
Correct |
46 ms |
452 KB |
Output is correct |
67 |
Correct |
64 ms |
344 KB |
Output is correct |
68 |
Correct |
85 ms |
332 KB |
Output is correct |
69 |
Correct |
101 ms |
332 KB |
Output is correct |
70 |
Correct |
83 ms |
332 KB |
Output is correct |
71 |
Correct |
88 ms |
352 KB |
Output is correct |
72 |
Correct |
100 ms |
332 KB |
Output is correct |
73 |
Correct |
108 ms |
332 KB |
Output is correct |
74 |
Correct |
105 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
440 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
3 ms |
332 KB |
Output is correct |
13 |
Correct |
3 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 |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
332 KB |
Output is correct |
18 |
Correct |
4 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
4 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
4 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
332 KB |
Output is correct |
24 |
Correct |
4 ms |
332 KB |
Output is correct |
25 |
Correct |
5 ms |
332 KB |
Output is correct |
26 |
Correct |
11 ms |
344 KB |
Output is correct |
27 |
Correct |
14 ms |
332 KB |
Output is correct |
28 |
Correct |
20 ms |
356 KB |
Output is correct |
29 |
Correct |
20 ms |
348 KB |
Output is correct |
30 |
Correct |
22 ms |
360 KB |
Output is correct |
31 |
Correct |
22 ms |
352 KB |
Output is correct |
32 |
Correct |
19 ms |
352 KB |
Output is correct |
33 |
Correct |
22 ms |
352 KB |
Output is correct |
34 |
Correct |
20 ms |
332 KB |
Output is correct |
35 |
Correct |
33 ms |
332 KB |
Output is correct |
36 |
Correct |
53 ms |
332 KB |
Output is correct |
37 |
Correct |
62 ms |
332 KB |
Output is correct |
38 |
Correct |
75 ms |
332 KB |
Output is correct |
39 |
Correct |
73 ms |
356 KB |
Output is correct |
40 |
Correct |
84 ms |
332 KB |
Output is correct |
41 |
Correct |
75 ms |
332 KB |
Output is correct |
42 |
Correct |
75 ms |
356 KB |
Output is correct |
43 |
Correct |
27 ms |
332 KB |
Output is correct |
44 |
Correct |
63 ms |
332 KB |
Output is correct |
45 |
Correct |
85 ms |
332 KB |
Output is correct |
46 |
Correct |
111 ms |
368 KB |
Output is correct |
47 |
Correct |
82 ms |
364 KB |
Output is correct |
48 |
Correct |
86 ms |
332 KB |
Output is correct |
49 |
Correct |
100 ms |
332 KB |
Output is correct |
50 |
Correct |
100 ms |
356 KB |
Output is correct |
51 |
Correct |
112 ms |
332 KB |
Output is correct |
52 |
Correct |
33 ms |
460 KB |
Output is correct |
53 |
Correct |
52 ms |
460 KB |
Output is correct |
54 |
Correct |
103 ms |
568 KB |
Output is correct |
55 |
Correct |
97 ms |
460 KB |
Output is correct |
56 |
Correct |
356 ms |
844 KB |
Output is correct |
57 |
Correct |
347 ms |
844 KB |
Output is correct |
58 |
Correct |
318 ms |
844 KB |
Output is correct |
59 |
Correct |
292 ms |
964 KB |
Output is correct |
60 |
Correct |
311 ms |
844 KB |
Output is correct |
61 |
Correct |
106 ms |
332 KB |
Output is correct |
62 |
Correct |
53 ms |
524 KB |
Output is correct |
63 |
Correct |
106 ms |
588 KB |
Output is correct |
64 |
Correct |
91 ms |
588 KB |
Output is correct |
65 |
Correct |
177 ms |
588 KB |
Output is correct |
66 |
Correct |
267 ms |
780 KB |
Output is correct |
67 |
Correct |
322 ms |
844 KB |
Output is correct |
68 |
Correct |
371 ms |
844 KB |
Output is correct |
69 |
Correct |
351 ms |
848 KB |
Output is correct |