#include <bits/stdc++.h>
#define ll long long
#define N 2005
using namespace std;
bool dp[N][N];
int dp2[N];
int n,A,B;
ll ans,arr[N],sum=0;
void init()
{
cin >> n >> A >> B;
for(int i=1;i<=n;++i){
cin >> arr[i];
sum+=arr[i];
}
}
void solve()
{
int maxn=log2(sum)+1;
for(int i=maxn;i>=0;--i){
ll res=( ans|( ((ll)1<<i)-(ll)1 ) );
memset(dp,0,sizeof(dp));
dp[0][0]=true;
for(int j=1;j<=n;++j){ //第J個數
for(int k=1;k<=min(j,B);++k){ //分段數
ll SUM=0;
for(int t=j-1;t>=k-1;--t){ //分割點
SUM+=arr[t+1];
if(dp[t][k-1] && ((SUM|res)==res) ){
dp[j][k]=true;
break;
}
}
}
}
bool flag=false;
for(int j=A;j<=B;++j){
if(dp[n][j]){
flag=true;
break;
}
}
if(!flag)
ans|=((ll)1<<i);
}
}
void solve2()
{
int maxn=log2(sum)+1;
for(int i=maxn;i>=0;--i){
ll res=( ans|( ((ll)1<<i)-(ll)1 ) );
memset(dp2,0x7f,sizeof(dp2));
dp2[0]=0;
for(int j=1;j<=n;++j){
ll SUM=0;
for(int k=j-1;k>=0;--k){
SUM+=arr[k+1];
if((SUM|res)==res)
dp2[j]=min(dp2[j],dp2[k]+1);
}
}
if(dp2[n]>B)
ans|=((ll)1<<i);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
init();
if(A==1)
solve2();
else
solve();
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
248 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
8 ms |
4220 KB |
Output is correct |
15 |
Correct |
8 ms |
4344 KB |
Output is correct |
16 |
Correct |
9 ms |
4216 KB |
Output is correct |
17 |
Correct |
9 ms |
4216 KB |
Output is correct |
18 |
Correct |
8 ms |
4344 KB |
Output is correct |
19 |
Correct |
9 ms |
4344 KB |
Output is correct |
20 |
Correct |
9 ms |
4216 KB |
Output is correct |
21 |
Correct |
8 ms |
4216 KB |
Output is correct |
22 |
Correct |
8 ms |
4216 KB |
Output is correct |
23 |
Correct |
8 ms |
4216 KB |
Output is correct |
24 |
Correct |
9 ms |
4344 KB |
Output is correct |
25 |
Correct |
8 ms |
4216 KB |
Output is correct |
26 |
Correct |
8 ms |
4376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
280 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
504 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
8 ms |
4216 KB |
Output is correct |
15 |
Correct |
7 ms |
4216 KB |
Output is correct |
16 |
Correct |
8 ms |
4216 KB |
Output is correct |
17 |
Correct |
10 ms |
4216 KB |
Output is correct |
18 |
Correct |
8 ms |
4216 KB |
Output is correct |
19 |
Correct |
9 ms |
4216 KB |
Output is correct |
20 |
Correct |
8 ms |
4216 KB |
Output is correct |
21 |
Correct |
8 ms |
4220 KB |
Output is correct |
22 |
Correct |
10 ms |
4216 KB |
Output is correct |
23 |
Correct |
8 ms |
4344 KB |
Output is correct |
24 |
Correct |
8 ms |
4216 KB |
Output is correct |
25 |
Correct |
8 ms |
4344 KB |
Output is correct |
26 |
Correct |
8 ms |
4292 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
380 KB |
Output is correct |
29 |
Correct |
5 ms |
380 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
408 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
4216 KB |
Output is correct |
15 |
Correct |
7 ms |
4216 KB |
Output is correct |
16 |
Correct |
7 ms |
4220 KB |
Output is correct |
17 |
Correct |
8 ms |
4220 KB |
Output is correct |
18 |
Correct |
8 ms |
4216 KB |
Output is correct |
19 |
Correct |
8 ms |
4344 KB |
Output is correct |
20 |
Correct |
8 ms |
4216 KB |
Output is correct |
21 |
Correct |
9 ms |
4344 KB |
Output is correct |
22 |
Correct |
8 ms |
4216 KB |
Output is correct |
23 |
Correct |
8 ms |
4216 KB |
Output is correct |
24 |
Correct |
8 ms |
4216 KB |
Output is correct |
25 |
Correct |
8 ms |
4216 KB |
Output is correct |
26 |
Correct |
8 ms |
4344 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
380 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
6 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
380 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
6 ms |
380 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
46 |
Correct |
5 ms |
376 KB |
Output is correct |
47 |
Correct |
5 ms |
376 KB |
Output is correct |
48 |
Correct |
5 ms |
376 KB |
Output is correct |
49 |
Correct |
5 ms |
376 KB |
Output is correct |
50 |
Correct |
5 ms |
376 KB |
Output is correct |
51 |
Correct |
5 ms |
376 KB |
Output is correct |
52 |
Correct |
5 ms |
380 KB |
Output is correct |
53 |
Correct |
5 ms |
376 KB |
Output is correct |
54 |
Correct |
5 ms |
376 KB |
Output is correct |
55 |
Correct |
5 ms |
376 KB |
Output is correct |
56 |
Correct |
5 ms |
376 KB |
Output is correct |
57 |
Correct |
5 ms |
376 KB |
Output is correct |
58 |
Correct |
5 ms |
376 KB |
Output is correct |
59 |
Correct |
5 ms |
376 KB |
Output is correct |
60 |
Correct |
5 ms |
376 KB |
Output is correct |
61 |
Correct |
5 ms |
376 KB |
Output is correct |
62 |
Correct |
5 ms |
376 KB |
Output is correct |
63 |
Correct |
5 ms |
376 KB |
Output is correct |
64 |
Correct |
8 ms |
4216 KB |
Output is correct |
65 |
Correct |
14 ms |
4216 KB |
Output is correct |
66 |
Correct |
14 ms |
4216 KB |
Output is correct |
67 |
Correct |
14 ms |
4216 KB |
Output is correct |
68 |
Correct |
17 ms |
4348 KB |
Output is correct |
69 |
Correct |
20 ms |
4216 KB |
Output is correct |
70 |
Correct |
19 ms |
4344 KB |
Output is correct |
71 |
Correct |
13 ms |
4216 KB |
Output is correct |
72 |
Correct |
17 ms |
4220 KB |
Output is correct |
73 |
Correct |
19 ms |
4344 KB |
Output is correct |
74 |
Correct |
18 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
380 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
352 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
380 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
5 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
5 ms |
376 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
46 |
Correct |
5 ms |
504 KB |
Output is correct |
47 |
Correct |
6 ms |
376 KB |
Output is correct |
48 |
Correct |
5 ms |
376 KB |
Output is correct |
49 |
Correct |
5 ms |
376 KB |
Output is correct |
50 |
Correct |
5 ms |
376 KB |
Output is correct |
51 |
Correct |
5 ms |
376 KB |
Output is correct |
52 |
Correct |
13 ms |
376 KB |
Output is correct |
53 |
Correct |
18 ms |
376 KB |
Output is correct |
54 |
Correct |
30 ms |
376 KB |
Output is correct |
55 |
Correct |
27 ms |
376 KB |
Output is correct |
56 |
Correct |
95 ms |
376 KB |
Output is correct |
57 |
Correct |
92 ms |
376 KB |
Output is correct |
58 |
Correct |
95 ms |
380 KB |
Output is correct |
59 |
Correct |
96 ms |
376 KB |
Output is correct |
60 |
Correct |
107 ms |
504 KB |
Output is correct |
61 |
Correct |
6 ms |
376 KB |
Output is correct |
62 |
Correct |
19 ms |
376 KB |
Output is correct |
63 |
Correct |
31 ms |
376 KB |
Output is correct |
64 |
Correct |
29 ms |
376 KB |
Output is correct |
65 |
Correct |
48 ms |
376 KB |
Output is correct |
66 |
Correct |
79 ms |
428 KB |
Output is correct |
67 |
Correct |
100 ms |
376 KB |
Output is correct |
68 |
Correct |
111 ms |
376 KB |
Output is correct |
69 |
Correct |
101 ms |
376 KB |
Output is correct |