#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 2020
#define INF 1e9+7
using namespace std;
ll n,a,b,ar[N];
bool dp[N][N];
ll dp2[N];
ll psum[N];
ll get_sum(ll i,ll j)
{
if(i == 0)
return psum[j];
return psum[j]-psum[i-1];
}
bool ison(ll m,ll i)
{
return (m >> i)&1;
}
ll getp(ll b)
{
if(b <= 20)
return (1 << b);
return (getp(b-20) << 20);
}
void solve1()
{
ll off = 0;
for(ll bits = 42;bits >= 0;bits--)
{
ll check = off;
check |= getp(bits);
memset(dp,0,sizeof dp);
rep(i,0,n)
{
if(!(psum[i]&check))
dp[i][1] = 1;
}
rep(i,0,n)
{
rep(j,1,i+1)
{
if(((get_sum(j,i))&(check)))
continue;
rep(k,2,b+1)
{
if(dp[j-1][k-1])
dp[i][k] = 1;
}
}
}
rep(i,a,b+1)
if(dp[n-1][i])
off = check;
}
ll ans = 0;
rep(bits,0,43)
{
if(!ison(off,bits))
ans |= getp(bits);
}
cout << ans;
return;
}
void solve2()
{
ll off = 0;
for(ll bits = 42;bits >= 0;bits--)
{
ll check = off;
check |= getp(bits);
rep(i,0,n)
{
if(!(psum[i]&check))
dp2[i] = 1;
else
dp2[i] = n+1;
}
rep(i,0,n)
{
rep(j,1,i+1)
{
if(!(get_sum(j,i)&check))
dp2[i] = min(dp2[i],dp2[j-1]+1);
}
}
if(dp2[n-1] <= b)
off = check;
}
ll ans = 0;
rep(bits,0,43)
{
if(!ison(off,bits))
ans |= getp(bits);
}
cout << ans << endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> a >> b;
memset(dp,-1,sizeof dp);
rep(i,0,n)
{
cin >> ar[i];
if(i == 0)
psum[i] = ar[i];
else
psum[i] = ar[i]+psum[i-1];
}
if(n <= 100)
solve1();
else
solve2();
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4352 KB |
Output is correct |
2 |
Correct |
13 ms |
4352 KB |
Output is correct |
3 |
Correct |
13 ms |
4352 KB |
Output is correct |
4 |
Correct |
13 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
4352 KB |
Output is correct |
6 |
Correct |
13 ms |
4352 KB |
Output is correct |
7 |
Correct |
13 ms |
4352 KB |
Output is correct |
8 |
Correct |
14 ms |
4352 KB |
Output is correct |
9 |
Correct |
12 ms |
4352 KB |
Output is correct |
10 |
Correct |
13 ms |
4352 KB |
Output is correct |
11 |
Correct |
13 ms |
4352 KB |
Output is correct |
12 |
Correct |
13 ms |
4352 KB |
Output is correct |
13 |
Correct |
13 ms |
4352 KB |
Output is correct |
14 |
Correct |
13 ms |
4352 KB |
Output is correct |
15 |
Correct |
12 ms |
4352 KB |
Output is correct |
16 |
Correct |
13 ms |
4352 KB |
Output is correct |
17 |
Correct |
13 ms |
4352 KB |
Output is correct |
18 |
Correct |
13 ms |
4352 KB |
Output is correct |
19 |
Correct |
13 ms |
4352 KB |
Output is correct |
20 |
Correct |
13 ms |
4352 KB |
Output is correct |
21 |
Correct |
13 ms |
4352 KB |
Output is correct |
22 |
Correct |
13 ms |
4352 KB |
Output is correct |
23 |
Correct |
14 ms |
4352 KB |
Output is correct |
24 |
Correct |
13 ms |
4324 KB |
Output is correct |
25 |
Correct |
14 ms |
4352 KB |
Output is correct |
26 |
Correct |
13 ms |
4352 KB |
Output is correct |
27 |
Correct |
13 ms |
4352 KB |
Output is correct |
28 |
Correct |
13 ms |
4352 KB |
Output is correct |
29 |
Correct |
13 ms |
4352 KB |
Output is correct |
30 |
Correct |
13 ms |
4352 KB |
Output is correct |
31 |
Correct |
12 ms |
4352 KB |
Output is correct |
32 |
Correct |
14 ms |
4352 KB |
Output is correct |
33 |
Correct |
13 ms |
4352 KB |
Output is correct |
34 |
Correct |
14 ms |
4352 KB |
Output is correct |
35 |
Correct |
13 ms |
4352 KB |
Output is correct |
36 |
Correct |
14 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4352 KB |
Output is correct |
2 |
Correct |
13 ms |
4352 KB |
Output is correct |
3 |
Correct |
13 ms |
4384 KB |
Output is correct |
4 |
Correct |
14 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
4324 KB |
Output is correct |
6 |
Correct |
12 ms |
4352 KB |
Output is correct |
7 |
Correct |
12 ms |
4352 KB |
Output is correct |
8 |
Correct |
13 ms |
4352 KB |
Output is correct |
9 |
Correct |
13 ms |
4352 KB |
Output is correct |
10 |
Correct |
13 ms |
4320 KB |
Output is correct |
11 |
Correct |
12 ms |
4352 KB |
Output is correct |
12 |
Correct |
12 ms |
4352 KB |
Output is correct |
13 |
Correct |
13 ms |
4352 KB |
Output is correct |
14 |
Correct |
13 ms |
4352 KB |
Output is correct |
15 |
Correct |
13 ms |
4384 KB |
Output is correct |
16 |
Correct |
13 ms |
4352 KB |
Output is correct |
17 |
Correct |
13 ms |
4352 KB |
Output is correct |
18 |
Correct |
13 ms |
4352 KB |
Output is correct |
19 |
Correct |
13 ms |
4352 KB |
Output is correct |
20 |
Correct |
13 ms |
4352 KB |
Output is correct |
21 |
Correct |
13 ms |
4352 KB |
Output is correct |
22 |
Correct |
12 ms |
4352 KB |
Output is correct |
23 |
Correct |
13 ms |
4352 KB |
Output is correct |
24 |
Correct |
13 ms |
4352 KB |
Output is correct |
25 |
Correct |
13 ms |
4352 KB |
Output is correct |
26 |
Correct |
13 ms |
4352 KB |
Output is correct |
27 |
Correct |
14 ms |
4352 KB |
Output is correct |
28 |
Correct |
13 ms |
4352 KB |
Output is correct |
29 |
Correct |
13 ms |
4352 KB |
Output is correct |
30 |
Correct |
14 ms |
4416 KB |
Output is correct |
31 |
Correct |
14 ms |
4352 KB |
Output is correct |
32 |
Correct |
14 ms |
4352 KB |
Output is correct |
33 |
Correct |
13 ms |
4352 KB |
Output is correct |
34 |
Correct |
13 ms |
4352 KB |
Output is correct |
35 |
Correct |
13 ms |
4352 KB |
Output is correct |
36 |
Correct |
13 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4352 KB |
Output is correct |
2 |
Correct |
14 ms |
4352 KB |
Output is correct |
3 |
Correct |
13 ms |
4352 KB |
Output is correct |
4 |
Correct |
13 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
4384 KB |
Output is correct |
6 |
Correct |
13 ms |
4352 KB |
Output is correct |
7 |
Correct |
12 ms |
4352 KB |
Output is correct |
8 |
Correct |
13 ms |
4352 KB |
Output is correct |
9 |
Correct |
14 ms |
4352 KB |
Output is correct |
10 |
Correct |
12 ms |
4352 KB |
Output is correct |
11 |
Correct |
12 ms |
4352 KB |
Output is correct |
12 |
Correct |
13 ms |
4352 KB |
Output is correct |
13 |
Correct |
13 ms |
4352 KB |
Output is correct |
14 |
Correct |
13 ms |
4352 KB |
Output is correct |
15 |
Correct |
13 ms |
4352 KB |
Output is correct |
16 |
Correct |
13 ms |
4352 KB |
Output is correct |
17 |
Correct |
13 ms |
4380 KB |
Output is correct |
18 |
Correct |
14 ms |
4352 KB |
Output is correct |
19 |
Correct |
14 ms |
4352 KB |
Output is correct |
20 |
Correct |
14 ms |
4352 KB |
Output is correct |
21 |
Correct |
13 ms |
4352 KB |
Output is correct |
22 |
Correct |
14 ms |
4352 KB |
Output is correct |
23 |
Correct |
14 ms |
4352 KB |
Output is correct |
24 |
Correct |
14 ms |
4316 KB |
Output is correct |
25 |
Correct |
14 ms |
4352 KB |
Output is correct |
26 |
Correct |
15 ms |
4480 KB |
Output is correct |
27 |
Correct |
21 ms |
4352 KB |
Output is correct |
28 |
Correct |
29 ms |
4352 KB |
Output is correct |
29 |
Correct |
28 ms |
4352 KB |
Output is correct |
30 |
Correct |
13 ms |
4352 KB |
Output is correct |
31 |
Correct |
21 ms |
4352 KB |
Output is correct |
32 |
Correct |
25 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4352 KB |
Output is correct |
2 |
Correct |
22 ms |
4352 KB |
Output is correct |
3 |
Correct |
13 ms |
4352 KB |
Output is correct |
4 |
Correct |
13 ms |
4352 KB |
Output is correct |
5 |
Correct |
14 ms |
4352 KB |
Output is correct |
6 |
Correct |
14 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
13 ms |
4352 KB |
Output is correct |
9 |
Correct |
15 ms |
4352 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
14 ms |
4352 KB |
Output is correct |
12 |
Correct |
15 ms |
4480 KB |
Output is correct |
13 |
Correct |
13 ms |
4352 KB |
Output is correct |
14 |
Correct |
12 ms |
4352 KB |
Output is correct |
15 |
Correct |
12 ms |
4352 KB |
Output is correct |
16 |
Correct |
13 ms |
4352 KB |
Output is correct |
17 |
Correct |
12 ms |
4352 KB |
Output is correct |
18 |
Correct |
13 ms |
4352 KB |
Output is correct |
19 |
Correct |
13 ms |
4352 KB |
Output is correct |
20 |
Correct |
12 ms |
4352 KB |
Output is correct |
21 |
Correct |
13 ms |
4352 KB |
Output is correct |
22 |
Correct |
12 ms |
4352 KB |
Output is correct |
23 |
Correct |
13 ms |
4352 KB |
Output is correct |
24 |
Correct |
13 ms |
4352 KB |
Output is correct |
25 |
Correct |
13 ms |
4352 KB |
Output is correct |
26 |
Correct |
13 ms |
4352 KB |
Output is correct |
27 |
Correct |
13 ms |
4352 KB |
Output is correct |
28 |
Correct |
13 ms |
4352 KB |
Output is correct |
29 |
Correct |
13 ms |
4352 KB |
Output is correct |
30 |
Correct |
14 ms |
4352 KB |
Output is correct |
31 |
Correct |
14 ms |
4352 KB |
Output is correct |
32 |
Correct |
14 ms |
4352 KB |
Output is correct |
33 |
Correct |
14 ms |
4352 KB |
Output is correct |
34 |
Correct |
13 ms |
4352 KB |
Output is correct |
35 |
Correct |
13 ms |
4480 KB |
Output is correct |
36 |
Correct |
13 ms |
4352 KB |
Output is correct |
37 |
Correct |
16 ms |
4352 KB |
Output is correct |
38 |
Correct |
24 ms |
4352 KB |
Output is correct |
39 |
Correct |
13 ms |
4352 KB |
Output is correct |
40 |
Correct |
14 ms |
4352 KB |
Output is correct |
41 |
Correct |
14 ms |
4352 KB |
Output is correct |
42 |
Correct |
13 ms |
4352 KB |
Output is correct |
43 |
Correct |
14 ms |
4352 KB |
Output is correct |
44 |
Correct |
14 ms |
4352 KB |
Output is correct |
45 |
Correct |
14 ms |
4352 KB |
Output is correct |
46 |
Correct |
14 ms |
4352 KB |
Output is correct |
47 |
Correct |
13 ms |
4352 KB |
Output is correct |
48 |
Correct |
13 ms |
4352 KB |
Output is correct |
49 |
Correct |
15 ms |
4352 KB |
Output is correct |
50 |
Correct |
21 ms |
4352 KB |
Output is correct |
51 |
Correct |
28 ms |
4352 KB |
Output is correct |
52 |
Correct |
28 ms |
4352 KB |
Output is correct |
53 |
Correct |
13 ms |
4352 KB |
Output is correct |
54 |
Correct |
20 ms |
4352 KB |
Output is correct |
55 |
Correct |
25 ms |
4352 KB |
Output is correct |
56 |
Correct |
14 ms |
4352 KB |
Output is correct |
57 |
Correct |
14 ms |
4352 KB |
Output is correct |
58 |
Correct |
15 ms |
4352 KB |
Output is correct |
59 |
Correct |
17 ms |
4352 KB |
Output is correct |
60 |
Correct |
18 ms |
4352 KB |
Output is correct |
61 |
Correct |
13 ms |
4352 KB |
Output is correct |
62 |
Correct |
21 ms |
4480 KB |
Output is correct |
63 |
Correct |
19 ms |
4352 KB |
Output is correct |
64 |
Correct |
27 ms |
4380 KB |
Output is correct |
65 |
Correct |
14 ms |
4352 KB |
Output is correct |
66 |
Correct |
14 ms |
4352 KB |
Output is correct |
67 |
Correct |
15 ms |
4352 KB |
Output is correct |
68 |
Correct |
16 ms |
4352 KB |
Output is correct |
69 |
Correct |
17 ms |
4352 KB |
Output is correct |
70 |
Correct |
17 ms |
4352 KB |
Output is correct |
71 |
Correct |
14 ms |
4416 KB |
Output is correct |
72 |
Correct |
20 ms |
4352 KB |
Output is correct |
73 |
Correct |
18 ms |
4352 KB |
Output is correct |
74 |
Correct |
19 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4472 KB |
Output is correct |
2 |
Correct |
13 ms |
4380 KB |
Output is correct |
3 |
Correct |
14 ms |
4352 KB |
Output is correct |
4 |
Correct |
13 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
4352 KB |
Output is correct |
6 |
Correct |
14 ms |
4352 KB |
Output is correct |
7 |
Correct |
13 ms |
4352 KB |
Output is correct |
8 |
Correct |
15 ms |
4352 KB |
Output is correct |
9 |
Correct |
13 ms |
4352 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
13 ms |
4352 KB |
Output is correct |
12 |
Correct |
14 ms |
4352 KB |
Output is correct |
13 |
Correct |
14 ms |
4352 KB |
Output is correct |
14 |
Correct |
13 ms |
4352 KB |
Output is correct |
15 |
Correct |
14 ms |
4352 KB |
Output is correct |
16 |
Correct |
13 ms |
4352 KB |
Output is correct |
17 |
Correct |
13 ms |
4352 KB |
Output is correct |
18 |
Correct |
15 ms |
4352 KB |
Output is correct |
19 |
Correct |
15 ms |
4352 KB |
Output is correct |
20 |
Correct |
13 ms |
4352 KB |
Output is correct |
21 |
Correct |
13 ms |
4352 KB |
Output is correct |
22 |
Correct |
12 ms |
4352 KB |
Output is correct |
23 |
Correct |
13 ms |
4352 KB |
Output is correct |
24 |
Correct |
13 ms |
4384 KB |
Output is correct |
25 |
Correct |
13 ms |
4352 KB |
Output is correct |
26 |
Correct |
13 ms |
4352 KB |
Output is correct |
27 |
Correct |
13 ms |
4352 KB |
Output is correct |
28 |
Correct |
13 ms |
4352 KB |
Output is correct |
29 |
Correct |
15 ms |
4480 KB |
Output is correct |
30 |
Correct |
13 ms |
4352 KB |
Output is correct |
31 |
Correct |
14 ms |
4352 KB |
Output is correct |
32 |
Correct |
14 ms |
4352 KB |
Output is correct |
33 |
Correct |
14 ms |
4352 KB |
Output is correct |
34 |
Correct |
14 ms |
4352 KB |
Output is correct |
35 |
Correct |
13 ms |
4352 KB |
Output is correct |
36 |
Correct |
15 ms |
4352 KB |
Output is correct |
37 |
Correct |
21 ms |
4352 KB |
Output is correct |
38 |
Correct |
30 ms |
4352 KB |
Output is correct |
39 |
Correct |
28 ms |
4352 KB |
Output is correct |
40 |
Correct |
13 ms |
4352 KB |
Output is correct |
41 |
Correct |
21 ms |
4384 KB |
Output is correct |
42 |
Correct |
25 ms |
4352 KB |
Output is correct |
43 |
Correct |
12 ms |
4352 KB |
Output is correct |
44 |
Correct |
13 ms |
4352 KB |
Output is correct |
45 |
Correct |
15 ms |
4352 KB |
Output is correct |
46 |
Correct |
17 ms |
4352 KB |
Output is correct |
47 |
Correct |
17 ms |
4352 KB |
Output is correct |
48 |
Correct |
14 ms |
4352 KB |
Output is correct |
49 |
Correct |
21 ms |
4480 KB |
Output is correct |
50 |
Correct |
23 ms |
4352 KB |
Output is correct |
51 |
Correct |
5 ms |
4352 KB |
Output is correct |
52 |
Correct |
13 ms |
4352 KB |
Output is correct |
53 |
Correct |
18 ms |
4352 KB |
Output is correct |
54 |
Correct |
29 ms |
4352 KB |
Output is correct |
55 |
Correct |
27 ms |
4352 KB |
Output is correct |
56 |
Correct |
87 ms |
4480 KB |
Output is correct |
57 |
Correct |
88 ms |
4440 KB |
Output is correct |
58 |
Correct |
83 ms |
4480 KB |
Output is correct |
59 |
Correct |
84 ms |
4444 KB |
Output is correct |
60 |
Correct |
91 ms |
4480 KB |
Output is correct |
61 |
Correct |
5 ms |
4352 KB |
Output is correct |
62 |
Correct |
18 ms |
4352 KB |
Output is correct |
63 |
Correct |
28 ms |
4352 KB |
Output is correct |
64 |
Correct |
26 ms |
4352 KB |
Output is correct |
65 |
Correct |
46 ms |
4472 KB |
Output is correct |
66 |
Correct |
69 ms |
4480 KB |
Output is correct |
67 |
Correct |
87 ms |
4480 KB |
Output is correct |
68 |
Correct |
91 ms |
4472 KB |
Output is correct |
69 |
Correct |
85 ms |
4480 KB |
Output is correct |