#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
template<class T> inline bool chmin(T &a, T b){
if(a>b){a=b;return true;}
return false;
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){a=b;return true;}
return false;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;
int N,A,B;
int Y[2005];
bool dp[2005][2005];
int dp2[2005];
void solve1(){
int anti=0;
rev(i,40){
anti+=1ll<<i;
memset(dp,0,sizeof(dp));
dp[0][0]=true;
rep(j,N){
rep(k,B){
if(!dp[j][k])continue;
int sum=0;
for(int l=j;l<N;l++){
sum+=Y[l];
if((sum&anti)==0)dp[l+1][k+1]=true;
}
}
}
bool flag=false;
for(int j=A;j<=B;j++)flag|=dp[N][j];
if(!flag)anti^=1ll<<i;
}
cout<<(anti^((1ll<<40)-1))<<endl;
}
void solve2(){
int anti=0;
rev(i,50){
anti+=1ll<<i;
fill(dp2,dp2+N+1,inf);
dp2[0]=0;
rep(j,N){
int sum=0;
for(int k=j;k<N;k++){
sum+=Y[k];
if((anti&sum)==0)chmin(dp2[k+1],dp2[j]+1);
}
}
if(dp2[N]>B)anti^=1ll<<i;
}
cout<<(anti^((1ll<<50)-1))<<endl;
}
signed main(){
cin>>N>>A>>B;
rep(i,N)cin>>Y[i];
if(N<=100)solve1();
else solve2();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4224 KB |
Output is correct |
2 |
Correct |
7 ms |
4224 KB |
Output is correct |
3 |
Correct |
7 ms |
4224 KB |
Output is correct |
4 |
Correct |
8 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
4224 KB |
Output is correct |
6 |
Correct |
7 ms |
4224 KB |
Output is correct |
7 |
Correct |
7 ms |
4224 KB |
Output is correct |
8 |
Correct |
7 ms |
4224 KB |
Output is correct |
9 |
Correct |
7 ms |
4224 KB |
Output is correct |
10 |
Correct |
8 ms |
4224 KB |
Output is correct |
11 |
Correct |
7 ms |
4224 KB |
Output is correct |
12 |
Correct |
7 ms |
4224 KB |
Output is correct |
13 |
Correct |
7 ms |
4224 KB |
Output is correct |
14 |
Correct |
7 ms |
4224 KB |
Output is correct |
15 |
Correct |
7 ms |
4224 KB |
Output is correct |
16 |
Correct |
8 ms |
4224 KB |
Output is correct |
17 |
Correct |
7 ms |
4224 KB |
Output is correct |
18 |
Correct |
7 ms |
4224 KB |
Output is correct |
19 |
Correct |
8 ms |
4224 KB |
Output is correct |
20 |
Correct |
8 ms |
4224 KB |
Output is correct |
21 |
Correct |
7 ms |
4224 KB |
Output is correct |
22 |
Correct |
8 ms |
4224 KB |
Output is correct |
23 |
Correct |
7 ms |
4224 KB |
Output is correct |
24 |
Correct |
7 ms |
4224 KB |
Output is correct |
25 |
Correct |
9 ms |
4352 KB |
Output is correct |
26 |
Correct |
9 ms |
4224 KB |
Output is correct |
27 |
Correct |
7 ms |
4224 KB |
Output is correct |
28 |
Correct |
7 ms |
4224 KB |
Output is correct |
29 |
Correct |
7 ms |
4224 KB |
Output is correct |
30 |
Correct |
10 ms |
4224 KB |
Output is correct |
31 |
Correct |
8 ms |
4224 KB |
Output is correct |
32 |
Correct |
7 ms |
4224 KB |
Output is correct |
33 |
Correct |
7 ms |
4224 KB |
Output is correct |
34 |
Correct |
10 ms |
4224 KB |
Output is correct |
35 |
Correct |
7 ms |
4224 KB |
Output is correct |
36 |
Correct |
7 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4224 KB |
Output is correct |
2 |
Correct |
7 ms |
4224 KB |
Output is correct |
3 |
Correct |
7 ms |
4224 KB |
Output is correct |
4 |
Correct |
7 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
4224 KB |
Output is correct |
6 |
Correct |
7 ms |
4224 KB |
Output is correct |
7 |
Correct |
7 ms |
4224 KB |
Output is correct |
8 |
Correct |
7 ms |
4224 KB |
Output is correct |
9 |
Correct |
7 ms |
4224 KB |
Output is correct |
10 |
Correct |
10 ms |
4224 KB |
Output is correct |
11 |
Correct |
7 ms |
4224 KB |
Output is correct |
12 |
Correct |
8 ms |
4224 KB |
Output is correct |
13 |
Correct |
7 ms |
4224 KB |
Output is correct |
14 |
Correct |
7 ms |
4224 KB |
Output is correct |
15 |
Correct |
7 ms |
4224 KB |
Output is correct |
16 |
Correct |
7 ms |
4224 KB |
Output is correct |
17 |
Correct |
9 ms |
4224 KB |
Output is correct |
18 |
Correct |
7 ms |
4224 KB |
Output is correct |
19 |
Correct |
7 ms |
4224 KB |
Output is correct |
20 |
Correct |
9 ms |
4224 KB |
Output is correct |
21 |
Correct |
8 ms |
4224 KB |
Output is correct |
22 |
Correct |
7 ms |
4224 KB |
Output is correct |
23 |
Correct |
8 ms |
4224 KB |
Output is correct |
24 |
Correct |
7 ms |
4224 KB |
Output is correct |
25 |
Correct |
7 ms |
4224 KB |
Output is correct |
26 |
Correct |
9 ms |
4224 KB |
Output is correct |
27 |
Correct |
12 ms |
4224 KB |
Output is correct |
28 |
Correct |
9 ms |
4224 KB |
Output is correct |
29 |
Correct |
10 ms |
4352 KB |
Output is correct |
30 |
Correct |
7 ms |
4224 KB |
Output is correct |
31 |
Correct |
8 ms |
4224 KB |
Output is correct |
32 |
Correct |
7 ms |
4224 KB |
Output is correct |
33 |
Correct |
8 ms |
4224 KB |
Output is correct |
34 |
Correct |
8 ms |
4224 KB |
Output is correct |
35 |
Correct |
8 ms |
4224 KB |
Output is correct |
36 |
Correct |
7 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4224 KB |
Output is correct |
2 |
Correct |
7 ms |
4224 KB |
Output is correct |
3 |
Correct |
8 ms |
4224 KB |
Output is correct |
4 |
Correct |
9 ms |
4224 KB |
Output is correct |
5 |
Correct |
8 ms |
4224 KB |
Output is correct |
6 |
Correct |
10 ms |
4224 KB |
Output is correct |
7 |
Correct |
7 ms |
4224 KB |
Output is correct |
8 |
Correct |
7 ms |
4224 KB |
Output is correct |
9 |
Correct |
7 ms |
4224 KB |
Output is correct |
10 |
Correct |
9 ms |
4224 KB |
Output is correct |
11 |
Correct |
12 ms |
4224 KB |
Output is correct |
12 |
Correct |
9 ms |
4224 KB |
Output is correct |
13 |
Correct |
8 ms |
4224 KB |
Output is correct |
14 |
Correct |
9 ms |
4224 KB |
Output is correct |
15 |
Correct |
9 ms |
4224 KB |
Output is correct |
16 |
Correct |
9 ms |
4224 KB |
Output is correct |
17 |
Correct |
8 ms |
4224 KB |
Output is correct |
18 |
Correct |
8 ms |
4224 KB |
Output is correct |
19 |
Correct |
16 ms |
4224 KB |
Output is correct |
20 |
Correct |
10 ms |
4224 KB |
Output is correct |
21 |
Correct |
7 ms |
4224 KB |
Output is correct |
22 |
Correct |
11 ms |
4224 KB |
Output is correct |
23 |
Correct |
7 ms |
4224 KB |
Output is correct |
24 |
Correct |
11 ms |
4224 KB |
Output is correct |
25 |
Correct |
8 ms |
4224 KB |
Output is correct |
26 |
Correct |
8 ms |
4224 KB |
Output is correct |
27 |
Correct |
11 ms |
4224 KB |
Output is correct |
28 |
Correct |
15 ms |
4224 KB |
Output is correct |
29 |
Correct |
13 ms |
4224 KB |
Output is correct |
30 |
Correct |
7 ms |
4224 KB |
Output is correct |
31 |
Correct |
12 ms |
4224 KB |
Output is correct |
32 |
Correct |
13 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4224 KB |
Output is correct |
2 |
Correct |
7 ms |
4224 KB |
Output is correct |
3 |
Correct |
8 ms |
4224 KB |
Output is correct |
4 |
Correct |
7 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
4224 KB |
Output is correct |
6 |
Correct |
9 ms |
4224 KB |
Output is correct |
7 |
Correct |
8 ms |
4224 KB |
Output is correct |
8 |
Correct |
7 ms |
4224 KB |
Output is correct |
9 |
Correct |
7 ms |
4224 KB |
Output is correct |
10 |
Correct |
7 ms |
4224 KB |
Output is correct |
11 |
Correct |
7 ms |
4224 KB |
Output is correct |
12 |
Correct |
7 ms |
4224 KB |
Output is correct |
13 |
Correct |
8 ms |
4224 KB |
Output is correct |
14 |
Correct |
7 ms |
4224 KB |
Output is correct |
15 |
Correct |
7 ms |
4224 KB |
Output is correct |
16 |
Correct |
7 ms |
4224 KB |
Output is correct |
17 |
Correct |
7 ms |
4224 KB |
Output is correct |
18 |
Correct |
7 ms |
4224 KB |
Output is correct |
19 |
Correct |
16 ms |
4224 KB |
Output is correct |
20 |
Correct |
8 ms |
4224 KB |
Output is correct |
21 |
Correct |
8 ms |
4224 KB |
Output is correct |
22 |
Correct |
9 ms |
4352 KB |
Output is correct |
23 |
Correct |
7 ms |
4224 KB |
Output is correct |
24 |
Correct |
9 ms |
4260 KB |
Output is correct |
25 |
Correct |
7 ms |
4224 KB |
Output is correct |
26 |
Correct |
8 ms |
4224 KB |
Output is correct |
27 |
Correct |
14 ms |
4224 KB |
Output is correct |
28 |
Correct |
12 ms |
4224 KB |
Output is correct |
29 |
Correct |
8 ms |
4224 KB |
Output is correct |
30 |
Correct |
9 ms |
4304 KB |
Output is correct |
31 |
Correct |
8 ms |
4224 KB |
Output is correct |
32 |
Correct |
17 ms |
4308 KB |
Output is correct |
33 |
Correct |
17 ms |
4224 KB |
Output is correct |
34 |
Correct |
7 ms |
4224 KB |
Output is correct |
35 |
Correct |
7 ms |
4224 KB |
Output is correct |
36 |
Correct |
11 ms |
4224 KB |
Output is correct |
37 |
Correct |
8 ms |
4224 KB |
Output is correct |
38 |
Correct |
7 ms |
4224 KB |
Output is correct |
39 |
Correct |
8 ms |
4224 KB |
Output is correct |
40 |
Correct |
13 ms |
4224 KB |
Output is correct |
41 |
Correct |
8 ms |
4224 KB |
Output is correct |
42 |
Correct |
8 ms |
4224 KB |
Output is correct |
43 |
Correct |
8 ms |
4224 KB |
Output is correct |
44 |
Correct |
7 ms |
4224 KB |
Output is correct |
45 |
Correct |
7 ms |
4224 KB |
Output is correct |
46 |
Correct |
7 ms |
4224 KB |
Output is correct |
47 |
Correct |
8 ms |
4224 KB |
Output is correct |
48 |
Correct |
9 ms |
4224 KB |
Output is correct |
49 |
Correct |
14 ms |
4224 KB |
Output is correct |
50 |
Correct |
13 ms |
4224 KB |
Output is correct |
51 |
Correct |
13 ms |
4224 KB |
Output is correct |
52 |
Correct |
14 ms |
4224 KB |
Output is correct |
53 |
Correct |
7 ms |
4224 KB |
Output is correct |
54 |
Correct |
13 ms |
4224 KB |
Output is correct |
55 |
Correct |
13 ms |
4224 KB |
Output is correct |
56 |
Correct |
8 ms |
4224 KB |
Output is correct |
57 |
Correct |
8 ms |
4224 KB |
Output is correct |
58 |
Correct |
9 ms |
4224 KB |
Output is correct |
59 |
Correct |
9 ms |
4224 KB |
Output is correct |
60 |
Correct |
9 ms |
4224 KB |
Output is correct |
61 |
Correct |
8 ms |
4224 KB |
Output is correct |
62 |
Correct |
11 ms |
4224 KB |
Output is correct |
63 |
Correct |
10 ms |
4224 KB |
Output is correct |
64 |
Correct |
11 ms |
4224 KB |
Output is correct |
65 |
Correct |
7 ms |
4224 KB |
Output is correct |
66 |
Correct |
8 ms |
4224 KB |
Output is correct |
67 |
Correct |
8 ms |
4224 KB |
Output is correct |
68 |
Correct |
8 ms |
4224 KB |
Output is correct |
69 |
Correct |
12 ms |
4224 KB |
Output is correct |
70 |
Correct |
13 ms |
4352 KB |
Output is correct |
71 |
Correct |
7 ms |
4224 KB |
Output is correct |
72 |
Correct |
14 ms |
4352 KB |
Output is correct |
73 |
Correct |
11 ms |
4224 KB |
Output is correct |
74 |
Correct |
10 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4224 KB |
Output is correct |
2 |
Correct |
7 ms |
4224 KB |
Output is correct |
3 |
Correct |
7 ms |
4352 KB |
Output is correct |
4 |
Correct |
7 ms |
4224 KB |
Output is correct |
5 |
Correct |
8 ms |
4224 KB |
Output is correct |
6 |
Correct |
8 ms |
4224 KB |
Output is correct |
7 |
Correct |
7 ms |
4224 KB |
Output is correct |
8 |
Correct |
9 ms |
4224 KB |
Output is correct |
9 |
Correct |
10 ms |
4352 KB |
Output is correct |
10 |
Correct |
9 ms |
4224 KB |
Output is correct |
11 |
Correct |
7 ms |
4224 KB |
Output is correct |
12 |
Correct |
8 ms |
4224 KB |
Output is correct |
13 |
Correct |
8 ms |
4224 KB |
Output is correct |
14 |
Correct |
7 ms |
4224 KB |
Output is correct |
15 |
Correct |
9 ms |
4224 KB |
Output is correct |
16 |
Correct |
8 ms |
4224 KB |
Output is correct |
17 |
Correct |
8 ms |
4224 KB |
Output is correct |
18 |
Correct |
8 ms |
4224 KB |
Output is correct |
19 |
Correct |
7 ms |
4224 KB |
Output is correct |
20 |
Correct |
7 ms |
4224 KB |
Output is correct |
21 |
Correct |
8 ms |
4224 KB |
Output is correct |
22 |
Correct |
7 ms |
4224 KB |
Output is correct |
23 |
Correct |
8 ms |
4224 KB |
Output is correct |
24 |
Correct |
8 ms |
4224 KB |
Output is correct |
25 |
Correct |
8 ms |
4224 KB |
Output is correct |
26 |
Correct |
8 ms |
4224 KB |
Output is correct |
27 |
Correct |
7 ms |
4224 KB |
Output is correct |
28 |
Correct |
8 ms |
4224 KB |
Output is correct |
29 |
Correct |
8 ms |
4224 KB |
Output is correct |
30 |
Correct |
8 ms |
4224 KB |
Output is correct |
31 |
Correct |
8 ms |
4224 KB |
Output is correct |
32 |
Correct |
9 ms |
4352 KB |
Output is correct |
33 |
Correct |
8 ms |
4224 KB |
Output is correct |
34 |
Correct |
18 ms |
4224 KB |
Output is correct |
35 |
Correct |
8 ms |
4224 KB |
Output is correct |
36 |
Correct |
9 ms |
4224 KB |
Output is correct |
37 |
Correct |
11 ms |
4224 KB |
Output is correct |
38 |
Correct |
14 ms |
4224 KB |
Output is correct |
39 |
Correct |
17 ms |
4224 KB |
Output is correct |
40 |
Correct |
15 ms |
4224 KB |
Output is correct |
41 |
Correct |
11 ms |
4224 KB |
Output is correct |
42 |
Correct |
14 ms |
4224 KB |
Output is correct |
43 |
Correct |
8 ms |
4224 KB |
Output is correct |
44 |
Correct |
9 ms |
4224 KB |
Output is correct |
45 |
Correct |
11 ms |
4224 KB |
Output is correct |
46 |
Correct |
11 ms |
4224 KB |
Output is correct |
47 |
Correct |
12 ms |
4352 KB |
Output is correct |
48 |
Correct |
8 ms |
4224 KB |
Output is correct |
49 |
Correct |
10 ms |
4224 KB |
Output is correct |
50 |
Correct |
10 ms |
4224 KB |
Output is correct |
51 |
Correct |
1 ms |
384 KB |
Output is correct |
52 |
Correct |
12 ms |
384 KB |
Output is correct |
53 |
Correct |
18 ms |
384 KB |
Output is correct |
54 |
Correct |
37 ms |
384 KB |
Output is correct |
55 |
Correct |
38 ms |
384 KB |
Output is correct |
56 |
Correct |
124 ms |
384 KB |
Output is correct |
57 |
Correct |
147 ms |
384 KB |
Output is correct |
58 |
Correct |
126 ms |
384 KB |
Output is correct |
59 |
Correct |
126 ms |
508 KB |
Output is correct |
60 |
Correct |
130 ms |
384 KB |
Output is correct |
61 |
Correct |
1 ms |
384 KB |
Output is correct |
62 |
Correct |
20 ms |
384 KB |
Output is correct |
63 |
Correct |
33 ms |
384 KB |
Output is correct |
64 |
Correct |
36 ms |
384 KB |
Output is correct |
65 |
Correct |
64 ms |
408 KB |
Output is correct |
66 |
Correct |
109 ms |
384 KB |
Output is correct |
67 |
Correct |
142 ms |
504 KB |
Output is correct |
68 |
Correct |
138 ms |
504 KB |
Output is correct |
69 |
Correct |
134 ms |
384 KB |
Output is correct |