#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
const int N = 2005;
ll p[N];
ll sum(int l, int r) {
return p[r] - (l ? p[l - 1] : 0);
}
//dp[index][OR][number of subarrays] = 1 if possible to obtain such partition
ll dp[N][N];
ll excluded;
bool check(ll k, int n, vector<ll>& a, int A, int B) {
for(int i = 0;i < N; ++i) for(int j = 0;j < N; ++j) dp[i][j] = 0;
dp[0][0] = 1;
for(int i = 1; i <= n; ++i) {
for(int j = 0;j < i; ++j) {
ll s = sum(j, i - 1);
if((s & excluded) || (s & (1LL << k))) continue;
for(int x = 0;x < n; ++x) {
dp[i][x + 1] |= dp[j][x];
}
}
}
for(int j = A; j <= B; ++j) {
if(dp[n][j]) return true;
}
return false;
}
bool check2(ll k, int n, vector<ll>& a, ll A, ll B) {
for(int i = 0;i < N; ++i) for(int j = 0;j < N; ++j) dp[i][j] = INT_MAX;
dp[0][0] = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 0;j < i; ++j) {
ll s = sum(j, i - 1);
if((s & excluded) || (s & (1LL << k))) continue;
dp[i][0] = min(dp[i][0], dp[j][0] + 1);
}
}
return (dp[n][0] <= B);
}
void solve() {
ll n, A, B;
cin >> n >> A >> B;
vector<ll> a(n);
for(int i = 0;i < n; ++i) {
cin >> a[i];
p[i] = (i ? p[i - 1] : 0) + a[i];
}
if(n <= 100) {
ll ans = 0;
for(ll pw = 62; pw >= 0; --pw) {
if(check(pw, n, a, A, B)) {
excluded += (1LL << pw);
} else {
ans += (1LL << pw);
}
}
cout << ans << "\n";
} else {
ll ans = 0;
for(ll pw = 62; pw >= 0; --pw) {
if(check2(pw, n, a, A, B)) {
excluded += (1LL << pw);
} else {
ans += (1LL << pw);
}
}
cout << ans << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
218 ms |
31760 KB |
Output is correct |
2 |
Correct |
225 ms |
31760 KB |
Output is correct |
3 |
Correct |
252 ms |
31764 KB |
Output is correct |
4 |
Correct |
219 ms |
31764 KB |
Output is correct |
5 |
Correct |
225 ms |
31772 KB |
Output is correct |
6 |
Correct |
220 ms |
31772 KB |
Output is correct |
7 |
Correct |
221 ms |
31780 KB |
Output is correct |
8 |
Correct |
224 ms |
31764 KB |
Output is correct |
9 |
Correct |
240 ms |
31764 KB |
Output is correct |
10 |
Correct |
224 ms |
31772 KB |
Output is correct |
11 |
Correct |
242 ms |
31768 KB |
Output is correct |
12 |
Correct |
220 ms |
31772 KB |
Output is correct |
13 |
Correct |
224 ms |
31692 KB |
Output is correct |
14 |
Correct |
224 ms |
31692 KB |
Output is correct |
15 |
Correct |
215 ms |
31692 KB |
Output is correct |
16 |
Correct |
216 ms |
31692 KB |
Output is correct |
17 |
Correct |
223 ms |
31692 KB |
Output is correct |
18 |
Correct |
214 ms |
31764 KB |
Output is correct |
19 |
Correct |
214 ms |
31896 KB |
Output is correct |
20 |
Correct |
219 ms |
31764 KB |
Output is correct |
21 |
Correct |
218 ms |
31772 KB |
Output is correct |
22 |
Correct |
224 ms |
31764 KB |
Output is correct |
23 |
Correct |
231 ms |
31764 KB |
Output is correct |
24 |
Correct |
217 ms |
31776 KB |
Output is correct |
25 |
Correct |
221 ms |
31692 KB |
Output is correct |
26 |
Correct |
228 ms |
31764 KB |
Output is correct |
27 |
Correct |
211 ms |
31692 KB |
Output is correct |
28 |
Correct |
219 ms |
31672 KB |
Output is correct |
29 |
Correct |
220 ms |
31764 KB |
Output is correct |
30 |
Correct |
214 ms |
31768 KB |
Output is correct |
31 |
Correct |
240 ms |
31692 KB |
Output is correct |
32 |
Correct |
230 ms |
31808 KB |
Output is correct |
33 |
Correct |
221 ms |
31692 KB |
Output is correct |
34 |
Correct |
214 ms |
31768 KB |
Output is correct |
35 |
Correct |
215 ms |
31764 KB |
Output is correct |
36 |
Correct |
213 ms |
31764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
31692 KB |
Output is correct |
2 |
Correct |
222 ms |
31760 KB |
Output is correct |
3 |
Correct |
220 ms |
31764 KB |
Output is correct |
4 |
Correct |
215 ms |
31700 KB |
Output is correct |
5 |
Correct |
213 ms |
31768 KB |
Output is correct |
6 |
Correct |
214 ms |
31692 KB |
Output is correct |
7 |
Correct |
213 ms |
31772 KB |
Output is correct |
8 |
Correct |
220 ms |
31812 KB |
Output is correct |
9 |
Correct |
213 ms |
31764 KB |
Output is correct |
10 |
Correct |
215 ms |
31768 KB |
Output is correct |
11 |
Correct |
234 ms |
31692 KB |
Output is correct |
12 |
Correct |
221 ms |
31704 KB |
Output is correct |
13 |
Correct |
215 ms |
31692 KB |
Output is correct |
14 |
Correct |
214 ms |
31776 KB |
Output is correct |
15 |
Correct |
212 ms |
31692 KB |
Output is correct |
16 |
Correct |
212 ms |
31760 KB |
Output is correct |
17 |
Correct |
220 ms |
31768 KB |
Output is correct |
18 |
Correct |
215 ms |
31772 KB |
Output is correct |
19 |
Correct |
230 ms |
31768 KB |
Output is correct |
20 |
Correct |
216 ms |
31764 KB |
Output is correct |
21 |
Correct |
214 ms |
31812 KB |
Output is correct |
22 |
Correct |
218 ms |
31760 KB |
Output is correct |
23 |
Correct |
217 ms |
31764 KB |
Output is correct |
24 |
Correct |
220 ms |
31760 KB |
Output is correct |
25 |
Correct |
212 ms |
31764 KB |
Output is correct |
26 |
Correct |
212 ms |
31752 KB |
Output is correct |
27 |
Correct |
216 ms |
31812 KB |
Output is correct |
28 |
Correct |
212 ms |
31768 KB |
Output is correct |
29 |
Correct |
238 ms |
31704 KB |
Output is correct |
30 |
Correct |
217 ms |
31812 KB |
Output is correct |
31 |
Correct |
214 ms |
31764 KB |
Output is correct |
32 |
Correct |
225 ms |
31748 KB |
Output is correct |
33 |
Correct |
219 ms |
31772 KB |
Output is correct |
34 |
Correct |
232 ms |
31764 KB |
Output is correct |
35 |
Correct |
220 ms |
31776 KB |
Output is correct |
36 |
Correct |
216 ms |
31776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
31692 KB |
Output is correct |
2 |
Correct |
218 ms |
31764 KB |
Output is correct |
3 |
Correct |
223 ms |
31768 KB |
Output is correct |
4 |
Correct |
223 ms |
31868 KB |
Output is correct |
5 |
Correct |
221 ms |
31692 KB |
Output is correct |
6 |
Correct |
234 ms |
31696 KB |
Output is correct |
7 |
Correct |
216 ms |
31812 KB |
Output is correct |
8 |
Correct |
211 ms |
31764 KB |
Output is correct |
9 |
Correct |
212 ms |
31692 KB |
Output is correct |
10 |
Correct |
228 ms |
31808 KB |
Output is correct |
11 |
Correct |
219 ms |
31768 KB |
Output is correct |
12 |
Correct |
236 ms |
31692 KB |
Output is correct |
13 |
Correct |
220 ms |
31692 KB |
Output is correct |
14 |
Correct |
233 ms |
31784 KB |
Output is correct |
15 |
Correct |
216 ms |
31692 KB |
Output is correct |
16 |
Correct |
219 ms |
31780 KB |
Output is correct |
17 |
Correct |
218 ms |
31692 KB |
Output is correct |
18 |
Correct |
214 ms |
31768 KB |
Output is correct |
19 |
Correct |
239 ms |
31820 KB |
Output is correct |
20 |
Correct |
215 ms |
31692 KB |
Output is correct |
21 |
Correct |
214 ms |
31764 KB |
Output is correct |
22 |
Correct |
224 ms |
31836 KB |
Output is correct |
23 |
Correct |
214 ms |
31764 KB |
Output is correct |
24 |
Correct |
237 ms |
31768 KB |
Output is correct |
25 |
Correct |
223 ms |
31768 KB |
Output is correct |
26 |
Correct |
223 ms |
31768 KB |
Output is correct |
27 |
Correct |
235 ms |
31768 KB |
Output is correct |
28 |
Correct |
240 ms |
31772 KB |
Output is correct |
29 |
Correct |
249 ms |
31692 KB |
Output is correct |
30 |
Correct |
237 ms |
31768 KB |
Output is correct |
31 |
Correct |
232 ms |
31812 KB |
Output is correct |
32 |
Correct |
228 ms |
31768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
31756 KB |
Output is correct |
2 |
Correct |
224 ms |
31760 KB |
Output is correct |
3 |
Correct |
216 ms |
31692 KB |
Output is correct |
4 |
Correct |
211 ms |
31692 KB |
Output is correct |
5 |
Correct |
216 ms |
31812 KB |
Output is correct |
6 |
Correct |
212 ms |
31684 KB |
Output is correct |
7 |
Correct |
217 ms |
31764 KB |
Output is correct |
8 |
Correct |
221 ms |
31780 KB |
Output is correct |
9 |
Correct |
216 ms |
31692 KB |
Output is correct |
10 |
Correct |
237 ms |
31768 KB |
Output is correct |
11 |
Correct |
216 ms |
31764 KB |
Output is correct |
12 |
Correct |
214 ms |
31764 KB |
Output is correct |
13 |
Correct |
214 ms |
31772 KB |
Output is correct |
14 |
Correct |
219 ms |
31780 KB |
Output is correct |
15 |
Correct |
217 ms |
31692 KB |
Output is correct |
16 |
Correct |
212 ms |
31764 KB |
Output is correct |
17 |
Correct |
215 ms |
31812 KB |
Output is correct |
18 |
Correct |
211 ms |
31772 KB |
Output is correct |
19 |
Correct |
212 ms |
31764 KB |
Output is correct |
20 |
Correct |
216 ms |
31692 KB |
Output is correct |
21 |
Correct |
239 ms |
31772 KB |
Output is correct |
22 |
Correct |
211 ms |
31692 KB |
Output is correct |
23 |
Correct |
217 ms |
31764 KB |
Output is correct |
24 |
Correct |
220 ms |
31764 KB |
Output is correct |
25 |
Correct |
230 ms |
31692 KB |
Output is correct |
26 |
Correct |
217 ms |
31776 KB |
Output is correct |
27 |
Correct |
217 ms |
31764 KB |
Output is correct |
28 |
Correct |
210 ms |
31764 KB |
Output is correct |
29 |
Correct |
211 ms |
31820 KB |
Output is correct |
30 |
Correct |
216 ms |
31768 KB |
Output is correct |
31 |
Correct |
233 ms |
31664 KB |
Output is correct |
32 |
Correct |
215 ms |
31692 KB |
Output is correct |
33 |
Correct |
219 ms |
31768 KB |
Output is correct |
34 |
Correct |
221 ms |
31684 KB |
Output is correct |
35 |
Correct |
211 ms |
31740 KB |
Output is correct |
36 |
Correct |
215 ms |
31764 KB |
Output is correct |
37 |
Correct |
218 ms |
31764 KB |
Output is correct |
38 |
Correct |
214 ms |
31764 KB |
Output is correct |
39 |
Correct |
214 ms |
31768 KB |
Output is correct |
40 |
Correct |
214 ms |
31764 KB |
Output is correct |
41 |
Correct |
214 ms |
31692 KB |
Output is correct |
42 |
Correct |
224 ms |
31772 KB |
Output is correct |
43 |
Correct |
240 ms |
31764 KB |
Output is correct |
44 |
Correct |
217 ms |
31764 KB |
Output is correct |
45 |
Correct |
228 ms |
31692 KB |
Output is correct |
46 |
Correct |
238 ms |
31768 KB |
Output is correct |
47 |
Correct |
218 ms |
31764 KB |
Output is correct |
48 |
Correct |
228 ms |
31860 KB |
Output is correct |
49 |
Correct |
252 ms |
31768 KB |
Output is correct |
50 |
Correct |
233 ms |
31768 KB |
Output is correct |
51 |
Correct |
245 ms |
31692 KB |
Output is correct |
52 |
Correct |
229 ms |
31692 KB |
Output is correct |
53 |
Correct |
231 ms |
31768 KB |
Output is correct |
54 |
Correct |
231 ms |
31812 KB |
Output is correct |
55 |
Correct |
232 ms |
31772 KB |
Output is correct |
56 |
Correct |
220 ms |
31764 KB |
Output is correct |
57 |
Correct |
223 ms |
31692 KB |
Output is correct |
58 |
Correct |
226 ms |
31692 KB |
Output is correct |
59 |
Correct |
220 ms |
31692 KB |
Output is correct |
60 |
Correct |
228 ms |
31768 KB |
Output is correct |
61 |
Correct |
222 ms |
31820 KB |
Output is correct |
62 |
Correct |
226 ms |
31764 KB |
Output is correct |
63 |
Correct |
222 ms |
31692 KB |
Output is correct |
64 |
Correct |
230 ms |
31768 KB |
Output is correct |
65 |
Correct |
216 ms |
31764 KB |
Output is correct |
66 |
Correct |
218 ms |
31692 KB |
Output is correct |
67 |
Correct |
217 ms |
31780 KB |
Output is correct |
68 |
Correct |
220 ms |
31692 KB |
Output is correct |
69 |
Correct |
221 ms |
31780 KB |
Output is correct |
70 |
Correct |
233 ms |
31764 KB |
Output is correct |
71 |
Correct |
227 ms |
31780 KB |
Output is correct |
72 |
Correct |
229 ms |
31692 KB |
Output is correct |
73 |
Correct |
232 ms |
31820 KB |
Output is correct |
74 |
Correct |
222 ms |
31672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
31812 KB |
Output is correct |
2 |
Correct |
215 ms |
31780 KB |
Output is correct |
3 |
Correct |
210 ms |
31692 KB |
Output is correct |
4 |
Correct |
211 ms |
31772 KB |
Output is correct |
5 |
Correct |
219 ms |
31812 KB |
Output is correct |
6 |
Correct |
219 ms |
31768 KB |
Output is correct |
7 |
Correct |
210 ms |
31816 KB |
Output is correct |
8 |
Correct |
224 ms |
31768 KB |
Output is correct |
9 |
Correct |
213 ms |
31692 KB |
Output is correct |
10 |
Correct |
214 ms |
31764 KB |
Output is correct |
11 |
Correct |
224 ms |
31784 KB |
Output is correct |
12 |
Correct |
219 ms |
31692 KB |
Output is correct |
13 |
Correct |
225 ms |
31692 KB |
Output is correct |
14 |
Correct |
225 ms |
31776 KB |
Output is correct |
15 |
Correct |
214 ms |
31772 KB |
Output is correct |
16 |
Correct |
215 ms |
31712 KB |
Output is correct |
17 |
Correct |
217 ms |
31768 KB |
Output is correct |
18 |
Correct |
212 ms |
31692 KB |
Output is correct |
19 |
Correct |
212 ms |
31772 KB |
Output is correct |
20 |
Correct |
242 ms |
31768 KB |
Output is correct |
21 |
Correct |
213 ms |
31692 KB |
Output is correct |
22 |
Correct |
231 ms |
31764 KB |
Output is correct |
23 |
Correct |
223 ms |
31692 KB |
Output is correct |
24 |
Correct |
212 ms |
31768 KB |
Output is correct |
25 |
Correct |
213 ms |
31768 KB |
Output is correct |
26 |
Correct |
216 ms |
31768 KB |
Output is correct |
27 |
Correct |
213 ms |
31692 KB |
Output is correct |
28 |
Correct |
216 ms |
31692 KB |
Output is correct |
29 |
Correct |
231 ms |
31772 KB |
Output is correct |
30 |
Correct |
215 ms |
31768 KB |
Output is correct |
31 |
Correct |
229 ms |
31692 KB |
Output is correct |
32 |
Correct |
218 ms |
31784 KB |
Output is correct |
33 |
Correct |
217 ms |
31692 KB |
Output is correct |
34 |
Correct |
213 ms |
31768 KB |
Output is correct |
35 |
Correct |
220 ms |
31768 KB |
Output is correct |
36 |
Correct |
226 ms |
31764 KB |
Output is correct |
37 |
Correct |
232 ms |
31692 KB |
Output is correct |
38 |
Correct |
248 ms |
31768 KB |
Output is correct |
39 |
Correct |
230 ms |
31776 KB |
Output is correct |
40 |
Correct |
231 ms |
31700 KB |
Output is correct |
41 |
Correct |
242 ms |
31768 KB |
Output is correct |
42 |
Correct |
227 ms |
31692 KB |
Output is correct |
43 |
Correct |
228 ms |
31692 KB |
Output is correct |
44 |
Correct |
226 ms |
31780 KB |
Output is correct |
45 |
Correct |
219 ms |
31768 KB |
Output is correct |
46 |
Correct |
221 ms |
31776 KB |
Output is correct |
47 |
Correct |
234 ms |
31692 KB |
Output is correct |
48 |
Correct |
223 ms |
31764 KB |
Output is correct |
49 |
Correct |
224 ms |
31692 KB |
Output is correct |
50 |
Correct |
237 ms |
31768 KB |
Output is correct |
51 |
Correct |
257 ms |
31768 KB |
Output is correct |
52 |
Correct |
287 ms |
31692 KB |
Output is correct |
53 |
Correct |
314 ms |
31788 KB |
Output is correct |
54 |
Correct |
322 ms |
31792 KB |
Output is correct |
55 |
Correct |
333 ms |
31684 KB |
Output is correct |
56 |
Correct |
580 ms |
31812 KB |
Output is correct |
57 |
Correct |
583 ms |
31776 KB |
Output is correct |
58 |
Correct |
575 ms |
31816 KB |
Output is correct |
59 |
Correct |
572 ms |
31820 KB |
Output is correct |
60 |
Correct |
587 ms |
31832 KB |
Output is correct |
61 |
Correct |
258 ms |
31772 KB |
Output is correct |
62 |
Correct |
294 ms |
31788 KB |
Output is correct |
63 |
Correct |
324 ms |
31796 KB |
Output is correct |
64 |
Correct |
329 ms |
31856 KB |
Output is correct |
65 |
Correct |
393 ms |
31820 KB |
Output is correct |
66 |
Correct |
495 ms |
31820 KB |
Output is correct |
67 |
Correct |
584 ms |
31820 KB |
Output is correct |
68 |
Correct |
586 ms |
31820 KB |
Output is correct |
69 |
Correct |
593 ms |
31820 KB |
Output is correct |