#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 2e3 + 10;
const ll LOG = 43;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
ll n , x , y , A[MAXN] , ans = (1ll << LOG) - 1;
int dp[MAXN] , dp2[MAXN][MAXN];
int check(ll cur){
memset(dp , 0 , sizeof(dp));
memset(dp2 , 0 , sizeof(dp2));
dp2[0][0] = 1;
for(int i = 1 ; i <= n ; i++){
ll sum = 0;
dp[i] = MOD;
for(int j = i - 1 ; j >= 0 ; j--){
sum += A[j + 1];
if((sum | cur) != cur) continue;
if(x == 1){
dp[i] = min(dp[i] , dp[j] + 1);
continue;
}
for(int k = 1 ; k <= i ; k++){
dp2[i][k] |= dp2[j][k - 1];
}
}
}
if(x == 1) return (dp[n] <= y);
for(int i = x ; i <= y ; i++){
if(dp2[n][i]) return 1;
}
return 0;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> x >> y;
for(int i = 1 ; i <= n ; i++) cin >> A[i];
for(int i = LOG - 1 ; i >= 0 ; i--){
if(check(ans ^ (1ll << i))){
ans ^= (1ll << i);
}
}
cout << ans << endl;
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
16128 KB |
Output is correct |
2 |
Correct |
93 ms |
16128 KB |
Output is correct |
3 |
Correct |
93 ms |
16108 KB |
Output is correct |
4 |
Correct |
90 ms |
16220 KB |
Output is correct |
5 |
Correct |
92 ms |
16220 KB |
Output is correct |
6 |
Correct |
93 ms |
16108 KB |
Output is correct |
7 |
Correct |
91 ms |
16236 KB |
Output is correct |
8 |
Correct |
92 ms |
16108 KB |
Output is correct |
9 |
Correct |
91 ms |
16236 KB |
Output is correct |
10 |
Correct |
90 ms |
16108 KB |
Output is correct |
11 |
Correct |
93 ms |
16108 KB |
Output is correct |
12 |
Correct |
96 ms |
16108 KB |
Output is correct |
13 |
Correct |
91 ms |
16108 KB |
Output is correct |
14 |
Correct |
94 ms |
16108 KB |
Output is correct |
15 |
Correct |
93 ms |
16108 KB |
Output is correct |
16 |
Correct |
96 ms |
16128 KB |
Output is correct |
17 |
Correct |
93 ms |
16236 KB |
Output is correct |
18 |
Correct |
93 ms |
16108 KB |
Output is correct |
19 |
Correct |
92 ms |
16108 KB |
Output is correct |
20 |
Correct |
93 ms |
16108 KB |
Output is correct |
21 |
Correct |
93 ms |
16108 KB |
Output is correct |
22 |
Correct |
92 ms |
16108 KB |
Output is correct |
23 |
Correct |
92 ms |
16220 KB |
Output is correct |
24 |
Correct |
92 ms |
16236 KB |
Output is correct |
25 |
Correct |
94 ms |
16108 KB |
Output is correct |
26 |
Correct |
93 ms |
16108 KB |
Output is correct |
27 |
Correct |
95 ms |
16108 KB |
Output is correct |
28 |
Correct |
94 ms |
16236 KB |
Output is correct |
29 |
Correct |
93 ms |
16108 KB |
Output is correct |
30 |
Correct |
93 ms |
16236 KB |
Output is correct |
31 |
Correct |
93 ms |
16108 KB |
Output is correct |
32 |
Correct |
94 ms |
16108 KB |
Output is correct |
33 |
Correct |
88 ms |
16236 KB |
Output is correct |
34 |
Correct |
91 ms |
16108 KB |
Output is correct |
35 |
Correct |
92 ms |
16108 KB |
Output is correct |
36 |
Correct |
91 ms |
16108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
16108 KB |
Output is correct |
2 |
Correct |
95 ms |
16108 KB |
Output is correct |
3 |
Correct |
92 ms |
16108 KB |
Output is correct |
4 |
Correct |
93 ms |
16108 KB |
Output is correct |
5 |
Correct |
94 ms |
16108 KB |
Output is correct |
6 |
Correct |
95 ms |
16236 KB |
Output is correct |
7 |
Correct |
93 ms |
16236 KB |
Output is correct |
8 |
Correct |
92 ms |
16236 KB |
Output is correct |
9 |
Correct |
93 ms |
16108 KB |
Output is correct |
10 |
Correct |
93 ms |
16108 KB |
Output is correct |
11 |
Correct |
93 ms |
16108 KB |
Output is correct |
12 |
Correct |
95 ms |
16108 KB |
Output is correct |
13 |
Correct |
95 ms |
16236 KB |
Output is correct |
14 |
Correct |
95 ms |
16108 KB |
Output is correct |
15 |
Correct |
93 ms |
16364 KB |
Output is correct |
16 |
Correct |
96 ms |
16108 KB |
Output is correct |
17 |
Correct |
95 ms |
16108 KB |
Output is correct |
18 |
Correct |
96 ms |
16108 KB |
Output is correct |
19 |
Correct |
94 ms |
16348 KB |
Output is correct |
20 |
Correct |
96 ms |
16108 KB |
Output is correct |
21 |
Correct |
97 ms |
16236 KB |
Output is correct |
22 |
Correct |
93 ms |
16108 KB |
Output is correct |
23 |
Correct |
94 ms |
16108 KB |
Output is correct |
24 |
Correct |
95 ms |
16108 KB |
Output is correct |
25 |
Correct |
93 ms |
16108 KB |
Output is correct |
26 |
Correct |
91 ms |
16236 KB |
Output is correct |
27 |
Correct |
96 ms |
16108 KB |
Output is correct |
28 |
Correct |
93 ms |
16256 KB |
Output is correct |
29 |
Correct |
92 ms |
16108 KB |
Output is correct |
30 |
Correct |
95 ms |
16236 KB |
Output is correct |
31 |
Correct |
94 ms |
16108 KB |
Output is correct |
32 |
Correct |
92 ms |
16108 KB |
Output is correct |
33 |
Correct |
93 ms |
16236 KB |
Output is correct |
34 |
Correct |
93 ms |
16236 KB |
Output is correct |
35 |
Correct |
94 ms |
16108 KB |
Output is correct |
36 |
Correct |
94 ms |
16108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
16236 KB |
Output is correct |
2 |
Correct |
95 ms |
16220 KB |
Output is correct |
3 |
Correct |
94 ms |
16236 KB |
Output is correct |
4 |
Correct |
93 ms |
16108 KB |
Output is correct |
5 |
Correct |
95 ms |
16108 KB |
Output is correct |
6 |
Correct |
96 ms |
16236 KB |
Output is correct |
7 |
Correct |
92 ms |
16236 KB |
Output is correct |
8 |
Correct |
93 ms |
16108 KB |
Output is correct |
9 |
Correct |
94 ms |
16236 KB |
Output is correct |
10 |
Correct |
93 ms |
16236 KB |
Output is correct |
11 |
Correct |
93 ms |
16108 KB |
Output is correct |
12 |
Correct |
96 ms |
16236 KB |
Output is correct |
13 |
Correct |
95 ms |
16236 KB |
Output is correct |
14 |
Correct |
93 ms |
16108 KB |
Output is correct |
15 |
Correct |
93 ms |
16236 KB |
Output is correct |
16 |
Correct |
92 ms |
16108 KB |
Output is correct |
17 |
Correct |
93 ms |
16236 KB |
Output is correct |
18 |
Correct |
92 ms |
16128 KB |
Output is correct |
19 |
Correct |
92 ms |
16108 KB |
Output is correct |
20 |
Correct |
92 ms |
16108 KB |
Output is correct |
21 |
Correct |
93 ms |
16108 KB |
Output is correct |
22 |
Correct |
92 ms |
16108 KB |
Output is correct |
23 |
Correct |
94 ms |
16108 KB |
Output is correct |
24 |
Correct |
96 ms |
16108 KB |
Output is correct |
25 |
Correct |
94 ms |
16108 KB |
Output is correct |
26 |
Correct |
94 ms |
16108 KB |
Output is correct |
27 |
Correct |
97 ms |
16108 KB |
Output is correct |
28 |
Correct |
95 ms |
16108 KB |
Output is correct |
29 |
Correct |
94 ms |
16512 KB |
Output is correct |
30 |
Correct |
96 ms |
16108 KB |
Output is correct |
31 |
Correct |
95 ms |
16108 KB |
Output is correct |
32 |
Correct |
95 ms |
16108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
16364 KB |
Output is correct |
2 |
Correct |
96 ms |
16236 KB |
Output is correct |
3 |
Correct |
96 ms |
16236 KB |
Output is correct |
4 |
Correct |
93 ms |
16236 KB |
Output is correct |
5 |
Correct |
93 ms |
16108 KB |
Output is correct |
6 |
Correct |
96 ms |
16236 KB |
Output is correct |
7 |
Correct |
94 ms |
16108 KB |
Output is correct |
8 |
Correct |
94 ms |
16108 KB |
Output is correct |
9 |
Correct |
94 ms |
16108 KB |
Output is correct |
10 |
Correct |
94 ms |
16236 KB |
Output is correct |
11 |
Correct |
94 ms |
16108 KB |
Output is correct |
12 |
Correct |
94 ms |
16108 KB |
Output is correct |
13 |
Correct |
93 ms |
16108 KB |
Output is correct |
14 |
Correct |
91 ms |
16108 KB |
Output is correct |
15 |
Correct |
93 ms |
16108 KB |
Output is correct |
16 |
Correct |
92 ms |
16108 KB |
Output is correct |
17 |
Correct |
94 ms |
16108 KB |
Output is correct |
18 |
Correct |
93 ms |
16348 KB |
Output is correct |
19 |
Correct |
93 ms |
16108 KB |
Output is correct |
20 |
Correct |
95 ms |
16108 KB |
Output is correct |
21 |
Correct |
92 ms |
16236 KB |
Output is correct |
22 |
Correct |
94 ms |
16236 KB |
Output is correct |
23 |
Correct |
95 ms |
16236 KB |
Output is correct |
24 |
Correct |
93 ms |
16108 KB |
Output is correct |
25 |
Correct |
92 ms |
16236 KB |
Output is correct |
26 |
Correct |
95 ms |
16108 KB |
Output is correct |
27 |
Correct |
93 ms |
16108 KB |
Output is correct |
28 |
Correct |
93 ms |
16108 KB |
Output is correct |
29 |
Correct |
92 ms |
16108 KB |
Output is correct |
30 |
Correct |
97 ms |
16236 KB |
Output is correct |
31 |
Correct |
92 ms |
16236 KB |
Output is correct |
32 |
Correct |
94 ms |
16236 KB |
Output is correct |
33 |
Correct |
91 ms |
16108 KB |
Output is correct |
34 |
Correct |
90 ms |
16108 KB |
Output is correct |
35 |
Correct |
94 ms |
16108 KB |
Output is correct |
36 |
Correct |
102 ms |
16236 KB |
Output is correct |
37 |
Correct |
91 ms |
16108 KB |
Output is correct |
38 |
Correct |
92 ms |
16108 KB |
Output is correct |
39 |
Correct |
91 ms |
16108 KB |
Output is correct |
40 |
Correct |
93 ms |
16108 KB |
Output is correct |
41 |
Correct |
93 ms |
16108 KB |
Output is correct |
42 |
Correct |
92 ms |
16108 KB |
Output is correct |
43 |
Correct |
93 ms |
16236 KB |
Output is correct |
44 |
Correct |
95 ms |
16108 KB |
Output is correct |
45 |
Correct |
93 ms |
16236 KB |
Output is correct |
46 |
Correct |
91 ms |
16108 KB |
Output is correct |
47 |
Correct |
94 ms |
16108 KB |
Output is correct |
48 |
Correct |
92 ms |
16108 KB |
Output is correct |
49 |
Correct |
92 ms |
16108 KB |
Output is correct |
50 |
Correct |
95 ms |
16236 KB |
Output is correct |
51 |
Correct |
92 ms |
16108 KB |
Output is correct |
52 |
Correct |
92 ms |
16108 KB |
Output is correct |
53 |
Correct |
92 ms |
16236 KB |
Output is correct |
54 |
Correct |
92 ms |
16108 KB |
Output is correct |
55 |
Correct |
92 ms |
16108 KB |
Output is correct |
56 |
Correct |
91 ms |
16108 KB |
Output is correct |
57 |
Correct |
94 ms |
16236 KB |
Output is correct |
58 |
Correct |
92 ms |
16108 KB |
Output is correct |
59 |
Correct |
93 ms |
16236 KB |
Output is correct |
60 |
Correct |
92 ms |
16364 KB |
Output is correct |
61 |
Correct |
97 ms |
16108 KB |
Output is correct |
62 |
Correct |
94 ms |
16108 KB |
Output is correct |
63 |
Correct |
94 ms |
16108 KB |
Output is correct |
64 |
Correct |
100 ms |
16108 KB |
Output is correct |
65 |
Correct |
94 ms |
16108 KB |
Output is correct |
66 |
Correct |
92 ms |
16108 KB |
Output is correct |
67 |
Correct |
93 ms |
16108 KB |
Output is correct |
68 |
Correct |
96 ms |
16236 KB |
Output is correct |
69 |
Correct |
95 ms |
16108 KB |
Output is correct |
70 |
Correct |
94 ms |
16220 KB |
Output is correct |
71 |
Correct |
94 ms |
16108 KB |
Output is correct |
72 |
Correct |
96 ms |
16128 KB |
Output is correct |
73 |
Correct |
97 ms |
16148 KB |
Output is correct |
74 |
Correct |
97 ms |
16236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
16108 KB |
Output is correct |
2 |
Correct |
92 ms |
16108 KB |
Output is correct |
3 |
Correct |
91 ms |
16236 KB |
Output is correct |
4 |
Correct |
92 ms |
16236 KB |
Output is correct |
5 |
Correct |
94 ms |
16108 KB |
Output is correct |
6 |
Correct |
91 ms |
16108 KB |
Output is correct |
7 |
Correct |
91 ms |
16108 KB |
Output is correct |
8 |
Correct |
91 ms |
16220 KB |
Output is correct |
9 |
Correct |
93 ms |
16108 KB |
Output is correct |
10 |
Correct |
91 ms |
16108 KB |
Output is correct |
11 |
Correct |
91 ms |
16108 KB |
Output is correct |
12 |
Correct |
93 ms |
16108 KB |
Output is correct |
13 |
Correct |
93 ms |
16108 KB |
Output is correct |
14 |
Correct |
91 ms |
16108 KB |
Output is correct |
15 |
Correct |
92 ms |
16108 KB |
Output is correct |
16 |
Correct |
91 ms |
16108 KB |
Output is correct |
17 |
Correct |
91 ms |
16108 KB |
Output is correct |
18 |
Correct |
91 ms |
16236 KB |
Output is correct |
19 |
Correct |
96 ms |
16108 KB |
Output is correct |
20 |
Correct |
92 ms |
16108 KB |
Output is correct |
21 |
Correct |
93 ms |
16108 KB |
Output is correct |
22 |
Correct |
90 ms |
16236 KB |
Output is correct |
23 |
Correct |
90 ms |
16364 KB |
Output is correct |
24 |
Correct |
90 ms |
16108 KB |
Output is correct |
25 |
Correct |
91 ms |
16108 KB |
Output is correct |
26 |
Correct |
91 ms |
16108 KB |
Output is correct |
27 |
Correct |
92 ms |
16236 KB |
Output is correct |
28 |
Correct |
91 ms |
16108 KB |
Output is correct |
29 |
Correct |
92 ms |
16108 KB |
Output is correct |
30 |
Correct |
93 ms |
16108 KB |
Output is correct |
31 |
Correct |
93 ms |
16108 KB |
Output is correct |
32 |
Correct |
91 ms |
16108 KB |
Output is correct |
33 |
Correct |
92 ms |
16108 KB |
Output is correct |
34 |
Correct |
93 ms |
16236 KB |
Output is correct |
35 |
Correct |
92 ms |
16108 KB |
Output is correct |
36 |
Correct |
93 ms |
16236 KB |
Output is correct |
37 |
Correct |
92 ms |
16236 KB |
Output is correct |
38 |
Correct |
91 ms |
16108 KB |
Output is correct |
39 |
Correct |
95 ms |
16108 KB |
Output is correct |
40 |
Correct |
92 ms |
16108 KB |
Output is correct |
41 |
Correct |
92 ms |
16236 KB |
Output is correct |
42 |
Correct |
92 ms |
16108 KB |
Output is correct |
43 |
Correct |
92 ms |
16236 KB |
Output is correct |
44 |
Correct |
91 ms |
16220 KB |
Output is correct |
45 |
Correct |
91 ms |
16236 KB |
Output is correct |
46 |
Correct |
92 ms |
16108 KB |
Output is correct |
47 |
Correct |
90 ms |
16108 KB |
Output is correct |
48 |
Correct |
94 ms |
16236 KB |
Output is correct |
49 |
Correct |
95 ms |
16236 KB |
Output is correct |
50 |
Correct |
92 ms |
16108 KB |
Output is correct |
51 |
Correct |
94 ms |
16108 KB |
Output is correct |
52 |
Correct |
103 ms |
16108 KB |
Output is correct |
53 |
Correct |
108 ms |
16236 KB |
Output is correct |
54 |
Correct |
123 ms |
16364 KB |
Output is correct |
55 |
Correct |
122 ms |
16236 KB |
Output is correct |
56 |
Correct |
201 ms |
16236 KB |
Output is correct |
57 |
Correct |
201 ms |
16236 KB |
Output is correct |
58 |
Correct |
204 ms |
16236 KB |
Output is correct |
59 |
Correct |
195 ms |
16364 KB |
Output is correct |
60 |
Correct |
209 ms |
16236 KB |
Output is correct |
61 |
Correct |
94 ms |
16236 KB |
Output is correct |
62 |
Correct |
109 ms |
16236 KB |
Output is correct |
63 |
Correct |
124 ms |
16236 KB |
Output is correct |
64 |
Correct |
121 ms |
16236 KB |
Output is correct |
65 |
Correct |
148 ms |
16236 KB |
Output is correct |
66 |
Correct |
177 ms |
16236 KB |
Output is correct |
67 |
Correct |
198 ms |
16364 KB |
Output is correct |
68 |
Correct |
204 ms |
16236 KB |
Output is correct |
69 |
Correct |
197 ms |
16236 KB |
Output is correct |