#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (root+root)
#define sag (root+root+1)
#define orta ((bas+son)/2)
#define ll long long
#define pii pair<int,int>
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
const int N=2e3+5;
const int mod=1e9+7;
const int inf=1e9+7;
int n,a,b,i,j,k;
int dp[N][N],dp2[N];
ll A[N],t,ans;
char H[2005][2005],H2[2005][2005];
int f(int x,int s){
if(x==n+1 and s>=a and s<=b)
return 1;
int &r=dp[x][s];
if(r!=-1)
return r;
r=0;
for(int i=x ; i<=n ; i++)
if(H[x][i])
r|=f(i+1,s+1);
return r;
}
int f2(int x){
if(x==n+1)
return 0;
int &r=dp2[x];
if(r!=-1)
return r;
r=2005;
for(int i=x ; i<=n ; i++)
if(H[x][i])
r=min(r,f2(i+1)+1);
return r;
}
main(){
scanf("%d %d %d",&n,&a,&b);
for(i=1 ; i<=n ; i++){
scanf("%lld",A+i);
A[i]+=A[i-1];
for(j=i ; j<=n ; j++)
H[i][j]=1;
}
for(i=40 ; i>=0 ; i--){
memcpy(H2,H,sizeof H);
for(j=1 ; j<=n ; j++)
for(k=j ; k<=n ; k++)
if(H[j][k]){
t=A[k]-A[j-1];
if(t&(1LL<<i))
H[j][k]=0;
}
if(a==1){
memset(dp2,-1,sizeof dp2);
if(f2(1)>b){
ans+=1LL<<i;
memcpy(H,H2,sizeof H);
}
}
else {
memset(dp,-1,sizeof dp);
if(!f(1,0)){
ans+=1LL<<i;
memcpy(H,H2,sizeof H);
}
}
}
printf("%lld",ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25300 KB |
Output is correct |
2 |
Correct |
20 ms |
25300 KB |
Output is correct |
3 |
Correct |
15 ms |
25300 KB |
Output is correct |
4 |
Correct |
17 ms |
25300 KB |
Output is correct |
5 |
Correct |
17 ms |
25300 KB |
Output is correct |
6 |
Correct |
21 ms |
25300 KB |
Output is correct |
7 |
Correct |
21 ms |
25300 KB |
Output is correct |
8 |
Correct |
18 ms |
25300 KB |
Output is correct |
9 |
Correct |
21 ms |
25300 KB |
Output is correct |
10 |
Correct |
21 ms |
25300 KB |
Output is correct |
11 |
Correct |
21 ms |
25300 KB |
Output is correct |
12 |
Correct |
21 ms |
25300 KB |
Output is correct |
13 |
Correct |
14 ms |
25300 KB |
Output is correct |
14 |
Correct |
114 ms |
25300 KB |
Output is correct |
15 |
Correct |
117 ms |
25300 KB |
Output is correct |
16 |
Correct |
117 ms |
25300 KB |
Output is correct |
17 |
Correct |
114 ms |
25300 KB |
Output is correct |
18 |
Correct |
115 ms |
25300 KB |
Output is correct |
19 |
Correct |
111 ms |
25300 KB |
Output is correct |
20 |
Correct |
111 ms |
25300 KB |
Output is correct |
21 |
Correct |
110 ms |
25300 KB |
Output is correct |
22 |
Correct |
118 ms |
25300 KB |
Output is correct |
23 |
Correct |
113 ms |
25300 KB |
Output is correct |
24 |
Correct |
113 ms |
25300 KB |
Output is correct |
25 |
Correct |
110 ms |
25300 KB |
Output is correct |
26 |
Correct |
114 ms |
25300 KB |
Output is correct |
27 |
Correct |
26 ms |
25300 KB |
Output is correct |
28 |
Correct |
30 ms |
25300 KB |
Output is correct |
29 |
Correct |
31 ms |
25300 KB |
Output is correct |
30 |
Correct |
27 ms |
25300 KB |
Output is correct |
31 |
Correct |
21 ms |
25300 KB |
Output is correct |
32 |
Correct |
24 ms |
25300 KB |
Output is correct |
33 |
Correct |
24 ms |
25300 KB |
Output is correct |
34 |
Correct |
25 ms |
25300 KB |
Output is correct |
35 |
Correct |
28 ms |
25300 KB |
Output is correct |
36 |
Correct |
28 ms |
25300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
25300 KB |
Output is correct |
2 |
Correct |
16 ms |
25300 KB |
Output is correct |
3 |
Correct |
19 ms |
25300 KB |
Output is correct |
4 |
Correct |
21 ms |
25300 KB |
Output is correct |
5 |
Correct |
20 ms |
25300 KB |
Output is correct |
6 |
Correct |
17 ms |
25300 KB |
Output is correct |
7 |
Correct |
18 ms |
25300 KB |
Output is correct |
8 |
Correct |
17 ms |
25300 KB |
Output is correct |
9 |
Correct |
18 ms |
25300 KB |
Output is correct |
10 |
Correct |
21 ms |
25300 KB |
Output is correct |
11 |
Correct |
20 ms |
25300 KB |
Output is correct |
12 |
Correct |
12 ms |
25300 KB |
Output is correct |
13 |
Correct |
16 ms |
25300 KB |
Output is correct |
14 |
Correct |
117 ms |
25300 KB |
Output is correct |
15 |
Correct |
114 ms |
25300 KB |
Output is correct |
16 |
Correct |
114 ms |
25300 KB |
Output is correct |
17 |
Correct |
116 ms |
25300 KB |
Output is correct |
18 |
Correct |
119 ms |
25300 KB |
Output is correct |
19 |
Correct |
117 ms |
25300 KB |
Output is correct |
20 |
Correct |
115 ms |
25300 KB |
Output is correct |
21 |
Correct |
110 ms |
25300 KB |
Output is correct |
22 |
Correct |
111 ms |
25300 KB |
Output is correct |
23 |
Correct |
115 ms |
25300 KB |
Output is correct |
24 |
Correct |
110 ms |
25300 KB |
Output is correct |
25 |
Correct |
115 ms |
25300 KB |
Output is correct |
26 |
Correct |
115 ms |
25300 KB |
Output is correct |
27 |
Correct |
21 ms |
25300 KB |
Output is correct |
28 |
Correct |
20 ms |
25300 KB |
Output is correct |
29 |
Correct |
21 ms |
25300 KB |
Output is correct |
30 |
Correct |
21 ms |
25300 KB |
Output is correct |
31 |
Correct |
18 ms |
25300 KB |
Output is correct |
32 |
Correct |
21 ms |
25300 KB |
Output is correct |
33 |
Correct |
18 ms |
25300 KB |
Output is correct |
34 |
Correct |
14 ms |
25300 KB |
Output is correct |
35 |
Correct |
21 ms |
25300 KB |
Output is correct |
36 |
Correct |
18 ms |
25300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
25300 KB |
Output is correct |
2 |
Correct |
16 ms |
25300 KB |
Output is correct |
3 |
Correct |
19 ms |
25300 KB |
Output is correct |
4 |
Correct |
17 ms |
25300 KB |
Output is correct |
5 |
Correct |
21 ms |
25300 KB |
Output is correct |
6 |
Correct |
20 ms |
25300 KB |
Output is correct |
7 |
Correct |
18 ms |
25300 KB |
Output is correct |
8 |
Correct |
21 ms |
25300 KB |
Output is correct |
9 |
Correct |
21 ms |
25300 KB |
Output is correct |
10 |
Correct |
21 ms |
25300 KB |
Output is correct |
11 |
Correct |
20 ms |
25300 KB |
Output is correct |
12 |
Correct |
20 ms |
25300 KB |
Output is correct |
13 |
Correct |
20 ms |
25300 KB |
Output is correct |
14 |
Correct |
20 ms |
25300 KB |
Output is correct |
15 |
Correct |
17 ms |
25300 KB |
Output is correct |
16 |
Correct |
21 ms |
25300 KB |
Output is correct |
17 |
Correct |
21 ms |
25300 KB |
Output is correct |
18 |
Correct |
21 ms |
25300 KB |
Output is correct |
19 |
Correct |
18 ms |
25300 KB |
Output is correct |
20 |
Correct |
22 ms |
25300 KB |
Output is correct |
21 |
Correct |
21 ms |
25300 KB |
Output is correct |
22 |
Correct |
21 ms |
25300 KB |
Output is correct |
23 |
Correct |
21 ms |
25300 KB |
Output is correct |
24 |
Correct |
21 ms |
25300 KB |
Output is correct |
25 |
Correct |
22 ms |
25300 KB |
Output is correct |
26 |
Correct |
22 ms |
25300 KB |
Output is correct |
27 |
Correct |
22 ms |
25300 KB |
Output is correct |
28 |
Correct |
19 ms |
25300 KB |
Output is correct |
29 |
Correct |
21 ms |
25300 KB |
Output is correct |
30 |
Correct |
20 ms |
25300 KB |
Output is correct |
31 |
Correct |
19 ms |
25300 KB |
Output is correct |
32 |
Correct |
23 ms |
25300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25300 KB |
Output is correct |
2 |
Correct |
20 ms |
25300 KB |
Output is correct |
3 |
Correct |
15 ms |
25300 KB |
Output is correct |
4 |
Correct |
17 ms |
25300 KB |
Output is correct |
5 |
Correct |
12 ms |
25300 KB |
Output is correct |
6 |
Correct |
20 ms |
25300 KB |
Output is correct |
7 |
Correct |
21 ms |
25300 KB |
Output is correct |
8 |
Correct |
21 ms |
25300 KB |
Output is correct |
9 |
Correct |
21 ms |
25300 KB |
Output is correct |
10 |
Correct |
18 ms |
25300 KB |
Output is correct |
11 |
Correct |
21 ms |
25300 KB |
Output is correct |
12 |
Correct |
18 ms |
25300 KB |
Output is correct |
13 |
Correct |
21 ms |
25300 KB |
Output is correct |
14 |
Correct |
117 ms |
25300 KB |
Output is correct |
15 |
Correct |
116 ms |
25300 KB |
Output is correct |
16 |
Correct |
115 ms |
25300 KB |
Output is correct |
17 |
Correct |
119 ms |
25300 KB |
Output is correct |
18 |
Correct |
107 ms |
25300 KB |
Output is correct |
19 |
Correct |
111 ms |
25300 KB |
Output is correct |
20 |
Correct |
112 ms |
25300 KB |
Output is correct |
21 |
Correct |
113 ms |
25300 KB |
Output is correct |
22 |
Correct |
112 ms |
25300 KB |
Output is correct |
23 |
Correct |
115 ms |
25300 KB |
Output is correct |
24 |
Correct |
114 ms |
25300 KB |
Output is correct |
25 |
Correct |
117 ms |
25300 KB |
Output is correct |
26 |
Correct |
114 ms |
25300 KB |
Output is correct |
27 |
Correct |
30 ms |
25300 KB |
Output is correct |
28 |
Correct |
28 ms |
25300 KB |
Output is correct |
29 |
Correct |
32 ms |
25300 KB |
Output is correct |
30 |
Correct |
32 ms |
25300 KB |
Output is correct |
31 |
Correct |
24 ms |
25300 KB |
Output is correct |
32 |
Correct |
24 ms |
25300 KB |
Output is correct |
33 |
Correct |
23 ms |
25300 KB |
Output is correct |
34 |
Correct |
21 ms |
25300 KB |
Output is correct |
35 |
Correct |
27 ms |
25300 KB |
Output is correct |
36 |
Correct |
27 ms |
25300 KB |
Output is correct |
37 |
Correct |
21 ms |
25300 KB |
Output is correct |
38 |
Correct |
21 ms |
25300 KB |
Output is correct |
39 |
Correct |
21 ms |
25300 KB |
Output is correct |
40 |
Correct |
21 ms |
25300 KB |
Output is correct |
41 |
Correct |
18 ms |
25300 KB |
Output is correct |
42 |
Correct |
21 ms |
25300 KB |
Output is correct |
43 |
Correct |
22 ms |
25300 KB |
Output is correct |
44 |
Correct |
21 ms |
25300 KB |
Output is correct |
45 |
Correct |
21 ms |
25300 KB |
Output is correct |
46 |
Correct |
22 ms |
25300 KB |
Output is correct |
47 |
Correct |
18 ms |
25300 KB |
Output is correct |
48 |
Correct |
18 ms |
25300 KB |
Output is correct |
49 |
Correct |
22 ms |
25300 KB |
Output is correct |
50 |
Correct |
18 ms |
25300 KB |
Output is correct |
51 |
Correct |
23 ms |
25300 KB |
Output is correct |
52 |
Correct |
21 ms |
25300 KB |
Output is correct |
53 |
Correct |
23 ms |
25300 KB |
Output is correct |
54 |
Correct |
19 ms |
25300 KB |
Output is correct |
55 |
Correct |
19 ms |
25300 KB |
Output is correct |
56 |
Correct |
32 ms |
25300 KB |
Output is correct |
57 |
Correct |
30 ms |
25300 KB |
Output is correct |
58 |
Correct |
32 ms |
25300 KB |
Output is correct |
59 |
Correct |
32 ms |
25300 KB |
Output is correct |
60 |
Correct |
22 ms |
25300 KB |
Output is correct |
61 |
Correct |
26 ms |
25300 KB |
Output is correct |
62 |
Correct |
32 ms |
25300 KB |
Output is correct |
63 |
Correct |
28 ms |
25300 KB |
Output is correct |
64 |
Correct |
142 ms |
25300 KB |
Output is correct |
65 |
Correct |
126 ms |
25300 KB |
Output is correct |
66 |
Correct |
127 ms |
25300 KB |
Output is correct |
67 |
Correct |
124 ms |
25300 KB |
Output is correct |
68 |
Correct |
129 ms |
25300 KB |
Output is correct |
69 |
Correct |
134 ms |
25300 KB |
Output is correct |
70 |
Correct |
126 ms |
25300 KB |
Output is correct |
71 |
Correct |
132 ms |
25300 KB |
Output is correct |
72 |
Correct |
136 ms |
25300 KB |
Output is correct |
73 |
Correct |
137 ms |
25300 KB |
Output is correct |
74 |
Correct |
136 ms |
25300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
25300 KB |
Output is correct |
2 |
Correct |
20 ms |
25300 KB |
Output is correct |
3 |
Correct |
19 ms |
25300 KB |
Output is correct |
4 |
Correct |
21 ms |
25300 KB |
Output is correct |
5 |
Correct |
20 ms |
25300 KB |
Output is correct |
6 |
Correct |
16 ms |
25300 KB |
Output is correct |
7 |
Correct |
18 ms |
25300 KB |
Output is correct |
8 |
Correct |
17 ms |
25300 KB |
Output is correct |
9 |
Correct |
18 ms |
25300 KB |
Output is correct |
10 |
Correct |
22 ms |
25300 KB |
Output is correct |
11 |
Correct |
20 ms |
25300 KB |
Output is correct |
12 |
Correct |
18 ms |
25300 KB |
Output is correct |
13 |
Correct |
17 ms |
25300 KB |
Output is correct |
14 |
Correct |
31 ms |
25300 KB |
Output is correct |
15 |
Correct |
27 ms |
25300 KB |
Output is correct |
16 |
Correct |
32 ms |
25300 KB |
Output is correct |
17 |
Correct |
32 ms |
25300 KB |
Output is correct |
18 |
Correct |
25 ms |
25300 KB |
Output is correct |
19 |
Correct |
20 ms |
25300 KB |
Output is correct |
20 |
Correct |
24 ms |
25300 KB |
Output is correct |
21 |
Correct |
20 ms |
25300 KB |
Output is correct |
22 |
Correct |
27 ms |
25300 KB |
Output is correct |
23 |
Correct |
24 ms |
25300 KB |
Output is correct |
24 |
Correct |
18 ms |
25300 KB |
Output is correct |
25 |
Correct |
18 ms |
25300 KB |
Output is correct |
26 |
Correct |
18 ms |
25300 KB |
Output is correct |
27 |
Correct |
17 ms |
25300 KB |
Output is correct |
28 |
Correct |
18 ms |
25300 KB |
Output is correct |
29 |
Correct |
17 ms |
25300 KB |
Output is correct |
30 |
Correct |
22 ms |
25300 KB |
Output is correct |
31 |
Correct |
18 ms |
25300 KB |
Output is correct |
32 |
Correct |
21 ms |
25300 KB |
Output is correct |
33 |
Correct |
18 ms |
25300 KB |
Output is correct |
34 |
Correct |
22 ms |
25300 KB |
Output is correct |
35 |
Correct |
21 ms |
25300 KB |
Output is correct |
36 |
Correct |
22 ms |
25300 KB |
Output is correct |
37 |
Correct |
18 ms |
25300 KB |
Output is correct |
38 |
Correct |
19 ms |
25300 KB |
Output is correct |
39 |
Correct |
18 ms |
25300 KB |
Output is correct |
40 |
Correct |
23 ms |
25300 KB |
Output is correct |
41 |
Correct |
19 ms |
25300 KB |
Output is correct |
42 |
Correct |
23 ms |
25300 KB |
Output is correct |
43 |
Correct |
32 ms |
25300 KB |
Output is correct |
44 |
Correct |
33 ms |
25300 KB |
Output is correct |
45 |
Correct |
29 ms |
25300 KB |
Output is correct |
46 |
Correct |
29 ms |
25300 KB |
Output is correct |
47 |
Correct |
25 ms |
25300 KB |
Output is correct |
48 |
Correct |
26 ms |
25300 KB |
Output is correct |
49 |
Correct |
32 ms |
25300 KB |
Output is correct |
50 |
Correct |
31 ms |
25300 KB |
Output is correct |
51 |
Correct |
29 ms |
25300 KB |
Output is correct |
52 |
Correct |
52 ms |
25300 KB |
Output is correct |
53 |
Correct |
56 ms |
25300 KB |
Output is correct |
54 |
Correct |
101 ms |
25300 KB |
Output is correct |
55 |
Correct |
87 ms |
25300 KB |
Output is correct |
56 |
Correct |
193 ms |
25300 KB |
Output is correct |
57 |
Correct |
181 ms |
25300 KB |
Output is correct |
58 |
Correct |
186 ms |
25300 KB |
Output is correct |
59 |
Correct |
210 ms |
25300 KB |
Output is correct |
60 |
Correct |
197 ms |
25300 KB |
Output is correct |
61 |
Correct |
32 ms |
25300 KB |
Output is correct |
62 |
Correct |
53 ms |
25300 KB |
Output is correct |
63 |
Correct |
104 ms |
25300 KB |
Output is correct |
64 |
Correct |
72 ms |
25300 KB |
Output is correct |
65 |
Correct |
106 ms |
25300 KB |
Output is correct |
66 |
Correct |
140 ms |
25300 KB |
Output is correct |
67 |
Correct |
175 ms |
25300 KB |
Output is correct |
68 |
Correct |
283 ms |
25300 KB |
Output is correct |
69 |
Correct |
174 ms |
25300 KB |
Output is correct |