#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e3+10,M=110;
ll dp[N];
ll a[N];
bool pd[N][N];
int32_t main(){
sync;
ll n;
cin >> n;
ll b;
ll e;
cin >> e >> b;
for (int i=1;i<=n;i++){
cin >> a[i];
}
if (n<110){
ll ans=((ll)1<<60)-1;
for (int bit=59;bit>-1;bit--){
ans-=((ll)1<<bit);
memset(pd,0,sizeof pd);
pd[0][0]=1;
for (int i=1;i<=n;i++){
ll cnt=0;
for (int j=i;j;j--){
cnt+=a[j];
for (int k=1;k<M;k++){
if ((cnt | ans)<=ans)
pd[i][k]=max(pd[i][k],pd[j-1][k-1]);
}
}
}
ll p1=0;
for (int i=e;i<=b;i++){
if (pd[n][i]) p1=1;
}
if (!p1){
ans+=((ll)1<<bit);
}
}
cout << ans << endl;
return 0;
}
ll ans=((ll)1<<60)-1;
for (int bit=59;bit>-1;bit--){
memset(dp,63,sizeof dp);
dp[0]=0;
ans-=((ll)1<<bit);
for (int i=1;i<=n;i++){
ll cnt=0;
for (int j=i;j;j--){
cnt+=a[j];
if ((cnt | ans)<=ans){
dp[i]=min(dp[i],dp[j-1]+1);
}
}
}
if (dp[n]>b){
ans+=((ll)1<<bit);
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
4224 KB |
Output is correct |
2 |
Correct |
14 ms |
4224 KB |
Output is correct |
3 |
Correct |
13 ms |
4224 KB |
Output is correct |
4 |
Correct |
15 ms |
4352 KB |
Output is correct |
5 |
Correct |
14 ms |
4224 KB |
Output is correct |
6 |
Correct |
14 ms |
4224 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
14 ms |
4224 KB |
Output is correct |
9 |
Correct |
14 ms |
4352 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
18 ms |
4224 KB |
Output is correct |
12 |
Correct |
15 ms |
4224 KB |
Output is correct |
13 |
Correct |
14 ms |
4224 KB |
Output is correct |
14 |
Correct |
14 ms |
4224 KB |
Output is correct |
15 |
Correct |
14 ms |
4352 KB |
Output is correct |
16 |
Correct |
14 ms |
4352 KB |
Output is correct |
17 |
Correct |
15 ms |
4224 KB |
Output is correct |
18 |
Correct |
15 ms |
4352 KB |
Output is correct |
19 |
Correct |
14 ms |
4352 KB |
Output is correct |
20 |
Correct |
14 ms |
4224 KB |
Output is correct |
21 |
Correct |
14 ms |
4352 KB |
Output is correct |
22 |
Correct |
14 ms |
4352 KB |
Output is correct |
23 |
Correct |
15 ms |
4352 KB |
Output is correct |
24 |
Correct |
16 ms |
4352 KB |
Output is correct |
25 |
Correct |
15 ms |
4352 KB |
Output is correct |
26 |
Correct |
15 ms |
4224 KB |
Output is correct |
27 |
Correct |
14 ms |
4224 KB |
Output is correct |
28 |
Correct |
17 ms |
4224 KB |
Output is correct |
29 |
Correct |
14 ms |
4352 KB |
Output is correct |
30 |
Correct |
16 ms |
4224 KB |
Output is correct |
31 |
Correct |
14 ms |
4352 KB |
Output is correct |
32 |
Correct |
15 ms |
4480 KB |
Output is correct |
33 |
Correct |
14 ms |
4352 KB |
Output is correct |
34 |
Correct |
14 ms |
4352 KB |
Output is correct |
35 |
Correct |
16 ms |
4224 KB |
Output is correct |
36 |
Correct |
16 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
4224 KB |
Output is correct |
2 |
Correct |
14 ms |
4224 KB |
Output is correct |
3 |
Correct |
14 ms |
4224 KB |
Output is correct |
4 |
Correct |
15 ms |
4352 KB |
Output is correct |
5 |
Correct |
17 ms |
4352 KB |
Output is correct |
6 |
Correct |
15 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4224 KB |
Output is correct |
8 |
Correct |
14 ms |
4224 KB |
Output is correct |
9 |
Correct |
14 ms |
4224 KB |
Output is correct |
10 |
Correct |
16 ms |
4224 KB |
Output is correct |
11 |
Correct |
14 ms |
4224 KB |
Output is correct |
12 |
Correct |
16 ms |
4352 KB |
Output is correct |
13 |
Correct |
15 ms |
4224 KB |
Output is correct |
14 |
Correct |
14 ms |
4352 KB |
Output is correct |
15 |
Correct |
15 ms |
4224 KB |
Output is correct |
16 |
Correct |
14 ms |
4224 KB |
Output is correct |
17 |
Correct |
14 ms |
4224 KB |
Output is correct |
18 |
Correct |
14 ms |
4224 KB |
Output is correct |
19 |
Correct |
15 ms |
4224 KB |
Output is correct |
20 |
Correct |
15 ms |
4224 KB |
Output is correct |
21 |
Correct |
15 ms |
4224 KB |
Output is correct |
22 |
Correct |
18 ms |
4352 KB |
Output is correct |
23 |
Correct |
15 ms |
4224 KB |
Output is correct |
24 |
Correct |
16 ms |
4224 KB |
Output is correct |
25 |
Correct |
15 ms |
4352 KB |
Output is correct |
26 |
Correct |
15 ms |
4224 KB |
Output is correct |
27 |
Correct |
15 ms |
4224 KB |
Output is correct |
28 |
Correct |
15 ms |
4224 KB |
Output is correct |
29 |
Correct |
18 ms |
4224 KB |
Output is correct |
30 |
Correct |
18 ms |
4224 KB |
Output is correct |
31 |
Correct |
19 ms |
4352 KB |
Output is correct |
32 |
Correct |
21 ms |
4224 KB |
Output is correct |
33 |
Correct |
23 ms |
4352 KB |
Output is correct |
34 |
Correct |
22 ms |
4224 KB |
Output is correct |
35 |
Correct |
19 ms |
4352 KB |
Output is correct |
36 |
Correct |
22 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4224 KB |
Output is correct |
2 |
Correct |
17 ms |
4224 KB |
Output is correct |
3 |
Correct |
15 ms |
4224 KB |
Output is correct |
4 |
Correct |
14 ms |
4224 KB |
Output is correct |
5 |
Correct |
19 ms |
4224 KB |
Output is correct |
6 |
Correct |
15 ms |
4224 KB |
Output is correct |
7 |
Correct |
15 ms |
4224 KB |
Output is correct |
8 |
Correct |
15 ms |
4224 KB |
Output is correct |
9 |
Correct |
15 ms |
4224 KB |
Output is correct |
10 |
Correct |
15 ms |
4224 KB |
Output is correct |
11 |
Correct |
14 ms |
4224 KB |
Output is correct |
12 |
Correct |
17 ms |
4224 KB |
Output is correct |
13 |
Correct |
15 ms |
4224 KB |
Output is correct |
14 |
Correct |
19 ms |
4224 KB |
Output is correct |
15 |
Correct |
16 ms |
4224 KB |
Output is correct |
16 |
Correct |
18 ms |
4224 KB |
Output is correct |
17 |
Correct |
18 ms |
4224 KB |
Output is correct |
18 |
Correct |
19 ms |
4224 KB |
Output is correct |
19 |
Correct |
19 ms |
4224 KB |
Output is correct |
20 |
Correct |
20 ms |
4224 KB |
Output is correct |
21 |
Correct |
27 ms |
4352 KB |
Output is correct |
22 |
Correct |
25 ms |
4224 KB |
Output is correct |
23 |
Correct |
27 ms |
4224 KB |
Output is correct |
24 |
Correct |
19 ms |
4224 KB |
Output is correct |
25 |
Correct |
23 ms |
4224 KB |
Output is correct |
26 |
Correct |
28 ms |
4224 KB |
Output is correct |
27 |
Correct |
35 ms |
4352 KB |
Output is correct |
28 |
Correct |
34 ms |
4224 KB |
Output is correct |
29 |
Correct |
34 ms |
4336 KB |
Output is correct |
30 |
Correct |
43 ms |
4352 KB |
Output is correct |
31 |
Correct |
41 ms |
4352 KB |
Output is correct |
32 |
Correct |
42 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4224 KB |
Output is correct |
2 |
Correct |
15 ms |
4224 KB |
Output is correct |
3 |
Correct |
17 ms |
4224 KB |
Output is correct |
4 |
Correct |
14 ms |
4224 KB |
Output is correct |
5 |
Correct |
14 ms |
4224 KB |
Output is correct |
6 |
Correct |
15 ms |
4224 KB |
Output is correct |
7 |
Correct |
15 ms |
4224 KB |
Output is correct |
8 |
Correct |
18 ms |
4224 KB |
Output is correct |
9 |
Correct |
16 ms |
4352 KB |
Output is correct |
10 |
Correct |
17 ms |
4224 KB |
Output is correct |
11 |
Correct |
16 ms |
4352 KB |
Output is correct |
12 |
Correct |
15 ms |
4224 KB |
Output is correct |
13 |
Correct |
15 ms |
4224 KB |
Output is correct |
14 |
Correct |
14 ms |
4224 KB |
Output is correct |
15 |
Correct |
14 ms |
4224 KB |
Output is correct |
16 |
Correct |
15 ms |
4224 KB |
Output is correct |
17 |
Correct |
15 ms |
4352 KB |
Output is correct |
18 |
Correct |
15 ms |
4224 KB |
Output is correct |
19 |
Correct |
15 ms |
4352 KB |
Output is correct |
20 |
Correct |
21 ms |
4224 KB |
Output is correct |
21 |
Correct |
15 ms |
4352 KB |
Output is correct |
22 |
Correct |
15 ms |
4224 KB |
Output is correct |
23 |
Correct |
17 ms |
4352 KB |
Output is correct |
24 |
Correct |
15 ms |
4352 KB |
Output is correct |
25 |
Correct |
17 ms |
4352 KB |
Output is correct |
26 |
Correct |
17 ms |
4224 KB |
Output is correct |
27 |
Correct |
13 ms |
4352 KB |
Output is correct |
28 |
Correct |
14 ms |
4224 KB |
Output is correct |
29 |
Correct |
14 ms |
4224 KB |
Output is correct |
30 |
Correct |
14 ms |
4224 KB |
Output is correct |
31 |
Correct |
15 ms |
4352 KB |
Output is correct |
32 |
Correct |
15 ms |
4352 KB |
Output is correct |
33 |
Correct |
15 ms |
4352 KB |
Output is correct |
34 |
Correct |
15 ms |
4224 KB |
Output is correct |
35 |
Correct |
26 ms |
4340 KB |
Output is correct |
36 |
Correct |
16 ms |
4224 KB |
Output is correct |
37 |
Correct |
17 ms |
4224 KB |
Output is correct |
38 |
Correct |
17 ms |
4352 KB |
Output is correct |
39 |
Correct |
20 ms |
4352 KB |
Output is correct |
40 |
Correct |
19 ms |
4224 KB |
Output is correct |
41 |
Correct |
21 ms |
4224 KB |
Output is correct |
42 |
Correct |
19 ms |
4352 KB |
Output is correct |
43 |
Correct |
19 ms |
4224 KB |
Output is correct |
44 |
Correct |
19 ms |
4224 KB |
Output is correct |
45 |
Correct |
21 ms |
4224 KB |
Output is correct |
46 |
Correct |
22 ms |
4352 KB |
Output is correct |
47 |
Correct |
22 ms |
4224 KB |
Output is correct |
48 |
Correct |
25 ms |
4224 KB |
Output is correct |
49 |
Correct |
26 ms |
4352 KB |
Output is correct |
50 |
Correct |
33 ms |
4224 KB |
Output is correct |
51 |
Correct |
39 ms |
4352 KB |
Output is correct |
52 |
Correct |
38 ms |
4352 KB |
Output is correct |
53 |
Correct |
44 ms |
4224 KB |
Output is correct |
54 |
Correct |
43 ms |
4352 KB |
Output is correct |
55 |
Correct |
39 ms |
4352 KB |
Output is correct |
56 |
Correct |
21 ms |
4224 KB |
Output is correct |
57 |
Correct |
24 ms |
4352 KB |
Output is correct |
58 |
Correct |
27 ms |
4472 KB |
Output is correct |
59 |
Correct |
26 ms |
4224 KB |
Output is correct |
60 |
Correct |
28 ms |
4352 KB |
Output is correct |
61 |
Correct |
33 ms |
4224 KB |
Output is correct |
62 |
Correct |
27 ms |
4352 KB |
Output is correct |
63 |
Correct |
31 ms |
4352 KB |
Output is correct |
64 |
Correct |
33 ms |
4224 KB |
Output is correct |
65 |
Correct |
22 ms |
4224 KB |
Output is correct |
66 |
Correct |
19 ms |
4224 KB |
Output is correct |
67 |
Correct |
22 ms |
4224 KB |
Output is correct |
68 |
Correct |
26 ms |
4352 KB |
Output is correct |
69 |
Correct |
26 ms |
4224 KB |
Output is correct |
70 |
Correct |
28 ms |
4224 KB |
Output is correct |
71 |
Correct |
31 ms |
4352 KB |
Output is correct |
72 |
Correct |
35 ms |
4352 KB |
Output is correct |
73 |
Correct |
28 ms |
4352 KB |
Output is correct |
74 |
Correct |
31 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4352 KB |
Output is correct |
2 |
Correct |
14 ms |
4352 KB |
Output is correct |
3 |
Correct |
18 ms |
4224 KB |
Output is correct |
4 |
Correct |
16 ms |
4352 KB |
Output is correct |
5 |
Correct |
17 ms |
4224 KB |
Output is correct |
6 |
Correct |
15 ms |
4224 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
17 ms |
4352 KB |
Output is correct |
9 |
Correct |
17 ms |
4224 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
15 ms |
4224 KB |
Output is correct |
12 |
Correct |
17 ms |
4352 KB |
Output is correct |
13 |
Correct |
17 ms |
4224 KB |
Output is correct |
14 |
Correct |
15 ms |
4224 KB |
Output is correct |
15 |
Correct |
22 ms |
4224 KB |
Output is correct |
16 |
Correct |
16 ms |
4352 KB |
Output is correct |
17 |
Correct |
18 ms |
4480 KB |
Output is correct |
18 |
Correct |
14 ms |
4224 KB |
Output is correct |
19 |
Correct |
15 ms |
4224 KB |
Output is correct |
20 |
Correct |
14 ms |
4224 KB |
Output is correct |
21 |
Correct |
14 ms |
4352 KB |
Output is correct |
22 |
Correct |
14 ms |
4224 KB |
Output is correct |
23 |
Correct |
15 ms |
4224 KB |
Output is correct |
24 |
Correct |
22 ms |
4352 KB |
Output is correct |
25 |
Correct |
17 ms |
4224 KB |
Output is correct |
26 |
Correct |
17 ms |
4224 KB |
Output is correct |
27 |
Correct |
19 ms |
4224 KB |
Output is correct |
28 |
Correct |
23 ms |
4480 KB |
Output is correct |
29 |
Correct |
19 ms |
4352 KB |
Output is correct |
30 |
Correct |
19 ms |
4224 KB |
Output is correct |
31 |
Correct |
19 ms |
4224 KB |
Output is correct |
32 |
Correct |
20 ms |
4352 KB |
Output is correct |
33 |
Correct |
20 ms |
4352 KB |
Output is correct |
34 |
Correct |
20 ms |
4224 KB |
Output is correct |
35 |
Correct |
22 ms |
4352 KB |
Output is correct |
36 |
Correct |
27 ms |
4224 KB |
Output is correct |
37 |
Correct |
32 ms |
4348 KB |
Output is correct |
38 |
Correct |
35 ms |
4224 KB |
Output is correct |
39 |
Correct |
36 ms |
4224 KB |
Output is correct |
40 |
Correct |
50 ms |
4352 KB |
Output is correct |
41 |
Correct |
37 ms |
4224 KB |
Output is correct |
42 |
Correct |
36 ms |
4224 KB |
Output is correct |
43 |
Correct |
17 ms |
4224 KB |
Output is correct |
44 |
Correct |
21 ms |
4352 KB |
Output is correct |
45 |
Correct |
26 ms |
4224 KB |
Output is correct |
46 |
Correct |
29 ms |
4224 KB |
Output is correct |
47 |
Correct |
24 ms |
4224 KB |
Output is correct |
48 |
Correct |
25 ms |
4224 KB |
Output is correct |
49 |
Correct |
28 ms |
4224 KB |
Output is correct |
50 |
Correct |
26 ms |
4224 KB |
Output is correct |
51 |
Correct |
25 ms |
4224 KB |
Output is correct |
52 |
Correct |
25 ms |
384 KB |
Output is correct |
53 |
Correct |
41 ms |
384 KB |
Output is correct |
54 |
Correct |
61 ms |
384 KB |
Output is correct |
55 |
Correct |
60 ms |
384 KB |
Output is correct |
56 |
Correct |
220 ms |
504 KB |
Output is correct |
57 |
Correct |
215 ms |
504 KB |
Output is correct |
58 |
Correct |
222 ms |
504 KB |
Output is correct |
59 |
Correct |
214 ms |
384 KB |
Output is correct |
60 |
Correct |
225 ms |
384 KB |
Output is correct |
61 |
Correct |
29 ms |
4224 KB |
Output is correct |
62 |
Correct |
37 ms |
384 KB |
Output is correct |
63 |
Correct |
61 ms |
384 KB |
Output is correct |
64 |
Correct |
59 ms |
384 KB |
Output is correct |
65 |
Correct |
109 ms |
384 KB |
Output is correct |
66 |
Correct |
167 ms |
416 KB |
Output is correct |
67 |
Correct |
214 ms |
504 KB |
Output is correct |
68 |
Correct |
218 ms |
384 KB |
Output is correct |
69 |
Correct |
216 ms |
384 KB |
Output is correct |