//In The Name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int N = 2010;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;
ll y[N], n, a, b;
ll dp1[N][N];
ll dp2[N];
bool check1(ll x){
for (int i = 0; i < N; i ++)
for (int j = 0; j < N; j ++)
dp1[i][j] = 0;
dp1[0][0] = 1;
for (int i = 1; i <= n; i ++){
ll s = 0;
for (int j = i; j; j --){
s += y[j];
if ((s | x) == x){
for (int k = 1; k <= n; k ++)
dp1[i][k] |= dp1[j - 1][k - 1];
}
}
}
for (int i = a; i <= b; i ++)
if (dp1[n][i])
return true;
return false;
}
bool check2(ll x){
for (int i = 0; i < N; i ++)
dp2[i] = N;
dp2[0] = 0;
for (int i = 1; i <= n; i ++){
ll s = 0;
for (int j = i; j; j --){
s += y[j];
if ((s | x) == x){
dp2[i] = min(dp2[i], dp2[j - 1] + 1);
}
}
}
return dp2[n] <= b;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> a >> b;
for (ll i = 1; i <= n; i ++)
cin >> y[i];
if (n <= 100){
ll ans = (1LL << 40) - 1;
for (ll i = 39; i >= 0; i --)
if (check1(ans ^ (1LL << i)))
ans ^= (1LL << i);
cout << ans;
return 0;
}
ll ans = (1LL << 45) - 1;
for (ll i = 44; i >= 0; i --)
if (check2(ans ^ (1LL << i)))
ans ^= (1LL << i);
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
31980 KB |
Output is correct |
2 |
Correct |
188 ms |
31980 KB |
Output is correct |
3 |
Correct |
185 ms |
31980 KB |
Output is correct |
4 |
Correct |
183 ms |
32108 KB |
Output is correct |
5 |
Correct |
181 ms |
31980 KB |
Output is correct |
6 |
Correct |
188 ms |
31980 KB |
Output is correct |
7 |
Correct |
187 ms |
31980 KB |
Output is correct |
8 |
Correct |
183 ms |
31980 KB |
Output is correct |
9 |
Correct |
187 ms |
31980 KB |
Output is correct |
10 |
Correct |
183 ms |
31980 KB |
Output is correct |
11 |
Correct |
185 ms |
31980 KB |
Output is correct |
12 |
Correct |
187 ms |
31980 KB |
Output is correct |
13 |
Correct |
187 ms |
31980 KB |
Output is correct |
14 |
Correct |
189 ms |
32028 KB |
Output is correct |
15 |
Correct |
183 ms |
31980 KB |
Output is correct |
16 |
Correct |
187 ms |
32108 KB |
Output is correct |
17 |
Correct |
189 ms |
32108 KB |
Output is correct |
18 |
Correct |
184 ms |
31980 KB |
Output is correct |
19 |
Correct |
188 ms |
31980 KB |
Output is correct |
20 |
Correct |
184 ms |
31980 KB |
Output is correct |
21 |
Correct |
180 ms |
31980 KB |
Output is correct |
22 |
Correct |
190 ms |
31980 KB |
Output is correct |
23 |
Correct |
187 ms |
32108 KB |
Output is correct |
24 |
Correct |
185 ms |
32028 KB |
Output is correct |
25 |
Correct |
186 ms |
32028 KB |
Output is correct |
26 |
Correct |
189 ms |
31980 KB |
Output is correct |
27 |
Correct |
191 ms |
31980 KB |
Output is correct |
28 |
Correct |
184 ms |
31980 KB |
Output is correct |
29 |
Correct |
194 ms |
32108 KB |
Output is correct |
30 |
Correct |
187 ms |
31980 KB |
Output is correct |
31 |
Correct |
190 ms |
31980 KB |
Output is correct |
32 |
Correct |
187 ms |
32108 KB |
Output is correct |
33 |
Correct |
191 ms |
32108 KB |
Output is correct |
34 |
Correct |
187 ms |
32108 KB |
Output is correct |
35 |
Correct |
191 ms |
31980 KB |
Output is correct |
36 |
Correct |
192 ms |
32128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
189 ms |
31980 KB |
Output is correct |
2 |
Correct |
193 ms |
32108 KB |
Output is correct |
3 |
Correct |
201 ms |
31980 KB |
Output is correct |
4 |
Correct |
181 ms |
32108 KB |
Output is correct |
5 |
Correct |
187 ms |
32108 KB |
Output is correct |
6 |
Correct |
203 ms |
31980 KB |
Output is correct |
7 |
Correct |
188 ms |
31980 KB |
Output is correct |
8 |
Correct |
186 ms |
31980 KB |
Output is correct |
9 |
Correct |
189 ms |
31980 KB |
Output is correct |
10 |
Correct |
182 ms |
31980 KB |
Output is correct |
11 |
Correct |
185 ms |
31980 KB |
Output is correct |
12 |
Correct |
192 ms |
31980 KB |
Output is correct |
13 |
Correct |
188 ms |
31980 KB |
Output is correct |
14 |
Correct |
185 ms |
31980 KB |
Output is correct |
15 |
Correct |
183 ms |
31980 KB |
Output is correct |
16 |
Correct |
185 ms |
31980 KB |
Output is correct |
17 |
Correct |
190 ms |
31980 KB |
Output is correct |
18 |
Correct |
183 ms |
32108 KB |
Output is correct |
19 |
Correct |
183 ms |
31980 KB |
Output is correct |
20 |
Correct |
189 ms |
32108 KB |
Output is correct |
21 |
Correct |
184 ms |
31980 KB |
Output is correct |
22 |
Correct |
187 ms |
31980 KB |
Output is correct |
23 |
Correct |
188 ms |
32028 KB |
Output is correct |
24 |
Correct |
183 ms |
31980 KB |
Output is correct |
25 |
Correct |
186 ms |
31980 KB |
Output is correct |
26 |
Correct |
184 ms |
32100 KB |
Output is correct |
27 |
Correct |
187 ms |
32108 KB |
Output is correct |
28 |
Correct |
189 ms |
32108 KB |
Output is correct |
29 |
Correct |
190 ms |
31980 KB |
Output is correct |
30 |
Correct |
190 ms |
32108 KB |
Output is correct |
31 |
Correct |
210 ms |
31980 KB |
Output is correct |
32 |
Correct |
188 ms |
31980 KB |
Output is correct |
33 |
Correct |
186 ms |
31980 KB |
Output is correct |
34 |
Correct |
185 ms |
32028 KB |
Output is correct |
35 |
Correct |
189 ms |
31980 KB |
Output is correct |
36 |
Correct |
185 ms |
32108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
32028 KB |
Output is correct |
2 |
Correct |
185 ms |
32108 KB |
Output is correct |
3 |
Correct |
190 ms |
31980 KB |
Output is correct |
4 |
Correct |
186 ms |
31980 KB |
Output is correct |
5 |
Correct |
188 ms |
31980 KB |
Output is correct |
6 |
Correct |
192 ms |
31980 KB |
Output is correct |
7 |
Correct |
186 ms |
31980 KB |
Output is correct |
8 |
Correct |
191 ms |
32108 KB |
Output is correct |
9 |
Correct |
188 ms |
31980 KB |
Output is correct |
10 |
Correct |
186 ms |
31980 KB |
Output is correct |
11 |
Correct |
184 ms |
31980 KB |
Output is correct |
12 |
Correct |
185 ms |
31980 KB |
Output is correct |
13 |
Correct |
192 ms |
32108 KB |
Output is correct |
14 |
Correct |
184 ms |
32108 KB |
Output is correct |
15 |
Correct |
188 ms |
31980 KB |
Output is correct |
16 |
Correct |
184 ms |
31980 KB |
Output is correct |
17 |
Correct |
183 ms |
32108 KB |
Output is correct |
18 |
Correct |
187 ms |
31980 KB |
Output is correct |
19 |
Correct |
191 ms |
31980 KB |
Output is correct |
20 |
Correct |
192 ms |
31980 KB |
Output is correct |
21 |
Correct |
190 ms |
31980 KB |
Output is correct |
22 |
Correct |
188 ms |
32028 KB |
Output is correct |
23 |
Correct |
191 ms |
32108 KB |
Output is correct |
24 |
Correct |
186 ms |
31980 KB |
Output is correct |
25 |
Correct |
193 ms |
31980 KB |
Output is correct |
26 |
Correct |
194 ms |
31980 KB |
Output is correct |
27 |
Correct |
204 ms |
31980 KB |
Output is correct |
28 |
Correct |
197 ms |
32108 KB |
Output is correct |
29 |
Correct |
206 ms |
31980 KB |
Output is correct |
30 |
Correct |
202 ms |
31980 KB |
Output is correct |
31 |
Correct |
193 ms |
31980 KB |
Output is correct |
32 |
Correct |
196 ms |
31980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
31980 KB |
Output is correct |
2 |
Correct |
182 ms |
31980 KB |
Output is correct |
3 |
Correct |
186 ms |
32108 KB |
Output is correct |
4 |
Correct |
187 ms |
31980 KB |
Output is correct |
5 |
Correct |
182 ms |
31980 KB |
Output is correct |
6 |
Correct |
190 ms |
31980 KB |
Output is correct |
7 |
Correct |
184 ms |
31980 KB |
Output is correct |
8 |
Correct |
190 ms |
31980 KB |
Output is correct |
9 |
Correct |
186 ms |
31980 KB |
Output is correct |
10 |
Correct |
188 ms |
31980 KB |
Output is correct |
11 |
Correct |
201 ms |
31980 KB |
Output is correct |
12 |
Correct |
181 ms |
32108 KB |
Output is correct |
13 |
Correct |
178 ms |
32028 KB |
Output is correct |
14 |
Correct |
200 ms |
31980 KB |
Output is correct |
15 |
Correct |
183 ms |
31980 KB |
Output is correct |
16 |
Correct |
182 ms |
31980 KB |
Output is correct |
17 |
Correct |
184 ms |
31980 KB |
Output is correct |
18 |
Correct |
184 ms |
32108 KB |
Output is correct |
19 |
Correct |
181 ms |
31980 KB |
Output is correct |
20 |
Correct |
188 ms |
31980 KB |
Output is correct |
21 |
Correct |
184 ms |
31980 KB |
Output is correct |
22 |
Correct |
183 ms |
31980 KB |
Output is correct |
23 |
Correct |
190 ms |
31980 KB |
Output is correct |
24 |
Correct |
180 ms |
31980 KB |
Output is correct |
25 |
Correct |
183 ms |
31980 KB |
Output is correct |
26 |
Correct |
191 ms |
31980 KB |
Output is correct |
27 |
Correct |
188 ms |
31980 KB |
Output is correct |
28 |
Correct |
182 ms |
31980 KB |
Output is correct |
29 |
Correct |
184 ms |
31980 KB |
Output is correct |
30 |
Correct |
184 ms |
31980 KB |
Output is correct |
31 |
Correct |
184 ms |
31968 KB |
Output is correct |
32 |
Correct |
186 ms |
32108 KB |
Output is correct |
33 |
Correct |
183 ms |
32108 KB |
Output is correct |
34 |
Correct |
184 ms |
31980 KB |
Output is correct |
35 |
Correct |
185 ms |
32108 KB |
Output is correct |
36 |
Correct |
183 ms |
31980 KB |
Output is correct |
37 |
Correct |
178 ms |
31980 KB |
Output is correct |
38 |
Correct |
184 ms |
32028 KB |
Output is correct |
39 |
Correct |
180 ms |
31980 KB |
Output is correct |
40 |
Correct |
189 ms |
32108 KB |
Output is correct |
41 |
Correct |
186 ms |
31980 KB |
Output is correct |
42 |
Correct |
183 ms |
32028 KB |
Output is correct |
43 |
Correct |
187 ms |
31980 KB |
Output is correct |
44 |
Correct |
179 ms |
31980 KB |
Output is correct |
45 |
Correct |
184 ms |
32108 KB |
Output is correct |
46 |
Correct |
183 ms |
31980 KB |
Output is correct |
47 |
Correct |
180 ms |
31980 KB |
Output is correct |
48 |
Correct |
181 ms |
31980 KB |
Output is correct |
49 |
Correct |
184 ms |
31980 KB |
Output is correct |
50 |
Correct |
191 ms |
32012 KB |
Output is correct |
51 |
Correct |
195 ms |
32108 KB |
Output is correct |
52 |
Correct |
194 ms |
31980 KB |
Output is correct |
53 |
Correct |
195 ms |
31980 KB |
Output is correct |
54 |
Correct |
198 ms |
31980 KB |
Output is correct |
55 |
Correct |
197 ms |
32108 KB |
Output is correct |
56 |
Correct |
180 ms |
31980 KB |
Output is correct |
57 |
Correct |
187 ms |
32108 KB |
Output is correct |
58 |
Correct |
180 ms |
31980 KB |
Output is correct |
59 |
Correct |
182 ms |
31980 KB |
Output is correct |
60 |
Correct |
184 ms |
31980 KB |
Output is correct |
61 |
Correct |
187 ms |
31980 KB |
Output is correct |
62 |
Correct |
183 ms |
32108 KB |
Output is correct |
63 |
Correct |
182 ms |
31980 KB |
Output is correct |
64 |
Correct |
197 ms |
32108 KB |
Output is correct |
65 |
Correct |
199 ms |
32108 KB |
Output is correct |
66 |
Correct |
177 ms |
31980 KB |
Output is correct |
67 |
Correct |
193 ms |
32108 KB |
Output is correct |
68 |
Correct |
189 ms |
31980 KB |
Output is correct |
69 |
Correct |
182 ms |
31980 KB |
Output is correct |
70 |
Correct |
197 ms |
32108 KB |
Output is correct |
71 |
Correct |
216 ms |
32028 KB |
Output is correct |
72 |
Correct |
195 ms |
32144 KB |
Output is correct |
73 |
Correct |
219 ms |
31980 KB |
Output is correct |
74 |
Correct |
189 ms |
32028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
31980 KB |
Output is correct |
2 |
Correct |
193 ms |
32108 KB |
Output is correct |
3 |
Correct |
192 ms |
32108 KB |
Output is correct |
4 |
Correct |
193 ms |
31980 KB |
Output is correct |
5 |
Correct |
194 ms |
32108 KB |
Output is correct |
6 |
Correct |
186 ms |
32108 KB |
Output is correct |
7 |
Correct |
197 ms |
31980 KB |
Output is correct |
8 |
Correct |
192 ms |
32108 KB |
Output is correct |
9 |
Correct |
185 ms |
31980 KB |
Output is correct |
10 |
Correct |
192 ms |
31980 KB |
Output is correct |
11 |
Correct |
195 ms |
32108 KB |
Output is correct |
12 |
Correct |
195 ms |
32108 KB |
Output is correct |
13 |
Correct |
187 ms |
32028 KB |
Output is correct |
14 |
Correct |
193 ms |
32108 KB |
Output is correct |
15 |
Correct |
192 ms |
32092 KB |
Output is correct |
16 |
Correct |
188 ms |
32108 KB |
Output is correct |
17 |
Correct |
190 ms |
31980 KB |
Output is correct |
18 |
Correct |
192 ms |
32028 KB |
Output is correct |
19 |
Correct |
186 ms |
31980 KB |
Output is correct |
20 |
Correct |
188 ms |
32108 KB |
Output is correct |
21 |
Correct |
181 ms |
31980 KB |
Output is correct |
22 |
Correct |
187 ms |
32028 KB |
Output is correct |
23 |
Correct |
186 ms |
31980 KB |
Output is correct |
24 |
Correct |
186 ms |
31980 KB |
Output is correct |
25 |
Correct |
187 ms |
31980 KB |
Output is correct |
26 |
Correct |
195 ms |
31980 KB |
Output is correct |
27 |
Correct |
194 ms |
32028 KB |
Output is correct |
28 |
Correct |
193 ms |
32028 KB |
Output is correct |
29 |
Correct |
193 ms |
31980 KB |
Output is correct |
30 |
Correct |
199 ms |
31980 KB |
Output is correct |
31 |
Correct |
187 ms |
31980 KB |
Output is correct |
32 |
Correct |
193 ms |
32028 KB |
Output is correct |
33 |
Correct |
188 ms |
32028 KB |
Output is correct |
34 |
Correct |
200 ms |
31908 KB |
Output is correct |
35 |
Correct |
203 ms |
31980 KB |
Output is correct |
36 |
Correct |
196 ms |
31980 KB |
Output is correct |
37 |
Correct |
195 ms |
32108 KB |
Output is correct |
38 |
Correct |
192 ms |
32028 KB |
Output is correct |
39 |
Correct |
208 ms |
31980 KB |
Output is correct |
40 |
Correct |
198 ms |
32028 KB |
Output is correct |
41 |
Correct |
197 ms |
31980 KB |
Output is correct |
42 |
Correct |
204 ms |
31980 KB |
Output is correct |
43 |
Correct |
180 ms |
31980 KB |
Output is correct |
44 |
Correct |
188 ms |
32028 KB |
Output is correct |
45 |
Correct |
189 ms |
31980 KB |
Output is correct |
46 |
Correct |
198 ms |
32028 KB |
Output is correct |
47 |
Correct |
197 ms |
32060 KB |
Output is correct |
48 |
Correct |
193 ms |
31980 KB |
Output is correct |
49 |
Correct |
197 ms |
31980 KB |
Output is correct |
50 |
Correct |
204 ms |
32028 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
13 ms |
364 KB |
Output is correct |
53 |
Correct |
27 ms |
364 KB |
Output is correct |
54 |
Correct |
45 ms |
440 KB |
Output is correct |
55 |
Correct |
49 ms |
408 KB |
Output is correct |
56 |
Correct |
126 ms |
364 KB |
Output is correct |
57 |
Correct |
125 ms |
452 KB |
Output is correct |
58 |
Correct |
121 ms |
436 KB |
Output is correct |
59 |
Correct |
126 ms |
364 KB |
Output is correct |
60 |
Correct |
133 ms |
456 KB |
Output is correct |
61 |
Correct |
2 ms |
364 KB |
Output is correct |
62 |
Correct |
20 ms |
492 KB |
Output is correct |
63 |
Correct |
37 ms |
364 KB |
Output is correct |
64 |
Correct |
33 ms |
364 KB |
Output is correct |
65 |
Correct |
63 ms |
444 KB |
Output is correct |
66 |
Correct |
100 ms |
452 KB |
Output is correct |
67 |
Correct |
136 ms |
452 KB |
Output is correct |
68 |
Correct |
140 ms |
364 KB |
Output is correct |
69 |
Correct |
123 ms |
464 KB |
Output is correct |