#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2000 + 5;
const ll ziad = 1e15 + 10;
int n, a[MAXN], A, B;
ll mx = 0;
bool ok[MAXN][MAXN];
ll dp[MAXN];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> A >> B;
for(int i = 0; i < n; i ++)
cin >> a[i];
if( n <= 300){
for(int b = 40; b >= 0; b --){
memset(ok, false, sizeof ok);
ok[0][0] = true;
//if( (a[0] & mx) == 0) ok[1][1] = true;
mx ^= (1LL << b);
for(int t = 0; t <= n; t ++){
for(int i = 0; i < n; i ++){
if( !ok[i][t] ) continue;
ll sum = 0;
for(int h = i; h < n; h ++){
sum += (ll)a[h];
if( (sum & mx) == 0) ok[h + 1][t + 1] = true;
}
}
}
bool bit = false;
for(int i = A; i <= B; i ++)
bit |= ok[n][i];
if( !bit )
mx ^= (1LL << b);
}
// cout << mx << endl;
mx = (1LL << 41) - 1 - mx;
cout << mx << endl;
return 0;
}
for(int b = 40; b >= 0; b --){
fill(dp, dp + n + 1, ziad);
dp[0] = 0;
// bool bit = false;
//if( (a[0] & mx) == 0) ok[1][1] = true;
mx ^= (1LL << b);
// for(int t = 0; t <= n; t ++){
for(int i = 0; i < n; i ++){
if( dp[i] >= B ) continue;
ll sum = 0;
for(int h = i; h < n; h ++){
sum += (ll)a[h];
if( (sum & mx) == 0){
dp[h + 1] = min(dp[h + 1], dp[i] + 1);
//
}
}
}
// }
if( dp[n] > B )
mx ^= (1LL << b);
}
mx = (1LL << 41) - 1 - mx;
cout << mx << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4332 KB |
Output is correct |
2 |
Correct |
9 ms |
4332 KB |
Output is correct |
3 |
Correct |
10 ms |
4332 KB |
Output is correct |
4 |
Correct |
10 ms |
4332 KB |
Output is correct |
5 |
Correct |
9 ms |
4332 KB |
Output is correct |
6 |
Correct |
10 ms |
4332 KB |
Output is correct |
7 |
Correct |
10 ms |
4332 KB |
Output is correct |
8 |
Correct |
9 ms |
4332 KB |
Output is correct |
9 |
Correct |
10 ms |
4332 KB |
Output is correct |
10 |
Correct |
9 ms |
4384 KB |
Output is correct |
11 |
Correct |
9 ms |
4332 KB |
Output is correct |
12 |
Correct |
9 ms |
4332 KB |
Output is correct |
13 |
Correct |
9 ms |
4332 KB |
Output is correct |
14 |
Correct |
9 ms |
4332 KB |
Output is correct |
15 |
Correct |
8 ms |
4332 KB |
Output is correct |
16 |
Correct |
9 ms |
4332 KB |
Output is correct |
17 |
Correct |
8 ms |
4332 KB |
Output is correct |
18 |
Correct |
9 ms |
4332 KB |
Output is correct |
19 |
Correct |
9 ms |
4332 KB |
Output is correct |
20 |
Correct |
9 ms |
4332 KB |
Output is correct |
21 |
Correct |
9 ms |
4332 KB |
Output is correct |
22 |
Correct |
9 ms |
4332 KB |
Output is correct |
23 |
Correct |
9 ms |
4460 KB |
Output is correct |
24 |
Correct |
9 ms |
4332 KB |
Output is correct |
25 |
Correct |
9 ms |
4332 KB |
Output is correct |
26 |
Correct |
11 ms |
4332 KB |
Output is correct |
27 |
Correct |
10 ms |
4332 KB |
Output is correct |
28 |
Correct |
11 ms |
4332 KB |
Output is correct |
29 |
Correct |
10 ms |
4332 KB |
Output is correct |
30 |
Correct |
10 ms |
4332 KB |
Output is correct |
31 |
Correct |
9 ms |
4332 KB |
Output is correct |
32 |
Correct |
9 ms |
4332 KB |
Output is correct |
33 |
Correct |
9 ms |
4332 KB |
Output is correct |
34 |
Correct |
9 ms |
4332 KB |
Output is correct |
35 |
Correct |
10 ms |
4332 KB |
Output is correct |
36 |
Correct |
9 ms |
4332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4332 KB |
Output is correct |
2 |
Correct |
9 ms |
4352 KB |
Output is correct |
3 |
Correct |
10 ms |
4332 KB |
Output is correct |
4 |
Correct |
9 ms |
4332 KB |
Output is correct |
5 |
Correct |
9 ms |
4332 KB |
Output is correct |
6 |
Correct |
9 ms |
4332 KB |
Output is correct |
7 |
Correct |
10 ms |
4332 KB |
Output is correct |
8 |
Correct |
10 ms |
4332 KB |
Output is correct |
9 |
Correct |
10 ms |
4332 KB |
Output is correct |
10 |
Correct |
9 ms |
4332 KB |
Output is correct |
11 |
Correct |
9 ms |
4332 KB |
Output is correct |
12 |
Correct |
10 ms |
4332 KB |
Output is correct |
13 |
Correct |
9 ms |
4332 KB |
Output is correct |
14 |
Correct |
10 ms |
4332 KB |
Output is correct |
15 |
Correct |
10 ms |
4332 KB |
Output is correct |
16 |
Correct |
9 ms |
4332 KB |
Output is correct |
17 |
Correct |
14 ms |
4332 KB |
Output is correct |
18 |
Correct |
9 ms |
4332 KB |
Output is correct |
19 |
Correct |
9 ms |
4332 KB |
Output is correct |
20 |
Correct |
10 ms |
4332 KB |
Output is correct |
21 |
Correct |
9 ms |
4332 KB |
Output is correct |
22 |
Correct |
10 ms |
4332 KB |
Output is correct |
23 |
Correct |
10 ms |
4332 KB |
Output is correct |
24 |
Correct |
9 ms |
4332 KB |
Output is correct |
25 |
Correct |
10 ms |
4460 KB |
Output is correct |
26 |
Correct |
9 ms |
4332 KB |
Output is correct |
27 |
Correct |
9 ms |
4332 KB |
Output is correct |
28 |
Correct |
8 ms |
4332 KB |
Output is correct |
29 |
Correct |
10 ms |
4332 KB |
Output is correct |
30 |
Correct |
10 ms |
4332 KB |
Output is correct |
31 |
Correct |
10 ms |
4332 KB |
Output is correct |
32 |
Correct |
10 ms |
4332 KB |
Output is correct |
33 |
Correct |
10 ms |
4332 KB |
Output is correct |
34 |
Correct |
9 ms |
4332 KB |
Output is correct |
35 |
Correct |
10 ms |
4332 KB |
Output is correct |
36 |
Correct |
11 ms |
4332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4332 KB |
Output is correct |
2 |
Correct |
8 ms |
4332 KB |
Output is correct |
3 |
Correct |
9 ms |
4332 KB |
Output is correct |
4 |
Correct |
9 ms |
4332 KB |
Output is correct |
5 |
Correct |
9 ms |
4332 KB |
Output is correct |
6 |
Correct |
10 ms |
4332 KB |
Output is correct |
7 |
Correct |
12 ms |
4332 KB |
Output is correct |
8 |
Correct |
9 ms |
4332 KB |
Output is correct |
9 |
Correct |
9 ms |
4352 KB |
Output is correct |
10 |
Correct |
9 ms |
4332 KB |
Output is correct |
11 |
Correct |
9 ms |
4332 KB |
Output is correct |
12 |
Correct |
9 ms |
4332 KB |
Output is correct |
13 |
Correct |
11 ms |
4332 KB |
Output is correct |
14 |
Correct |
9 ms |
4332 KB |
Output is correct |
15 |
Correct |
9 ms |
4332 KB |
Output is correct |
16 |
Correct |
9 ms |
4332 KB |
Output is correct |
17 |
Correct |
15 ms |
4332 KB |
Output is correct |
18 |
Correct |
11 ms |
4332 KB |
Output is correct |
19 |
Correct |
11 ms |
4332 KB |
Output is correct |
20 |
Correct |
14 ms |
4332 KB |
Output is correct |
21 |
Correct |
10 ms |
4332 KB |
Output is correct |
22 |
Correct |
10 ms |
4352 KB |
Output is correct |
23 |
Correct |
12 ms |
4332 KB |
Output is correct |
24 |
Correct |
11 ms |
4332 KB |
Output is correct |
25 |
Correct |
11 ms |
4332 KB |
Output is correct |
26 |
Correct |
13 ms |
4332 KB |
Output is correct |
27 |
Correct |
19 ms |
4332 KB |
Output is correct |
28 |
Correct |
18 ms |
4332 KB |
Output is correct |
29 |
Correct |
17 ms |
4332 KB |
Output is correct |
30 |
Correct |
18 ms |
4332 KB |
Output is correct |
31 |
Correct |
17 ms |
4336 KB |
Output is correct |
32 |
Correct |
17 ms |
4332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4332 KB |
Output is correct |
2 |
Correct |
8 ms |
4332 KB |
Output is correct |
3 |
Correct |
9 ms |
4332 KB |
Output is correct |
4 |
Correct |
9 ms |
4332 KB |
Output is correct |
5 |
Correct |
9 ms |
4332 KB |
Output is correct |
6 |
Correct |
10 ms |
4332 KB |
Output is correct |
7 |
Correct |
9 ms |
4332 KB |
Output is correct |
8 |
Correct |
9 ms |
4332 KB |
Output is correct |
9 |
Correct |
11 ms |
4332 KB |
Output is correct |
10 |
Correct |
9 ms |
4332 KB |
Output is correct |
11 |
Correct |
9 ms |
4332 KB |
Output is correct |
12 |
Correct |
8 ms |
4332 KB |
Output is correct |
13 |
Correct |
10 ms |
4332 KB |
Output is correct |
14 |
Correct |
9 ms |
4332 KB |
Output is correct |
15 |
Correct |
9 ms |
4332 KB |
Output is correct |
16 |
Correct |
8 ms |
4332 KB |
Output is correct |
17 |
Correct |
9 ms |
4332 KB |
Output is correct |
18 |
Correct |
9 ms |
4332 KB |
Output is correct |
19 |
Correct |
9 ms |
4332 KB |
Output is correct |
20 |
Correct |
9 ms |
4332 KB |
Output is correct |
21 |
Correct |
11 ms |
4332 KB |
Output is correct |
22 |
Correct |
11 ms |
4332 KB |
Output is correct |
23 |
Correct |
8 ms |
4332 KB |
Output is correct |
24 |
Correct |
9 ms |
4332 KB |
Output is correct |
25 |
Correct |
8 ms |
4332 KB |
Output is correct |
26 |
Correct |
8 ms |
4332 KB |
Output is correct |
27 |
Correct |
9 ms |
4332 KB |
Output is correct |
28 |
Correct |
9 ms |
4332 KB |
Output is correct |
29 |
Correct |
10 ms |
4332 KB |
Output is correct |
30 |
Correct |
9 ms |
4332 KB |
Output is correct |
31 |
Correct |
10 ms |
4332 KB |
Output is correct |
32 |
Correct |
9 ms |
4332 KB |
Output is correct |
33 |
Correct |
11 ms |
4332 KB |
Output is correct |
34 |
Correct |
9 ms |
4332 KB |
Output is correct |
35 |
Correct |
8 ms |
4332 KB |
Output is correct |
36 |
Correct |
9 ms |
4332 KB |
Output is correct |
37 |
Correct |
10 ms |
4332 KB |
Output is correct |
38 |
Correct |
9 ms |
4332 KB |
Output is correct |
39 |
Correct |
10 ms |
4332 KB |
Output is correct |
40 |
Correct |
9 ms |
4332 KB |
Output is correct |
41 |
Correct |
10 ms |
4332 KB |
Output is correct |
42 |
Correct |
10 ms |
4332 KB |
Output is correct |
43 |
Correct |
10 ms |
4332 KB |
Output is correct |
44 |
Correct |
10 ms |
4332 KB |
Output is correct |
45 |
Correct |
10 ms |
4332 KB |
Output is correct |
46 |
Correct |
10 ms |
4332 KB |
Output is correct |
47 |
Correct |
12 ms |
4332 KB |
Output is correct |
48 |
Correct |
16 ms |
4480 KB |
Output is correct |
49 |
Correct |
13 ms |
4332 KB |
Output is correct |
50 |
Correct |
15 ms |
4332 KB |
Output is correct |
51 |
Correct |
18 ms |
4332 KB |
Output is correct |
52 |
Correct |
17 ms |
4332 KB |
Output is correct |
53 |
Correct |
18 ms |
4332 KB |
Output is correct |
54 |
Correct |
17 ms |
4332 KB |
Output is correct |
55 |
Correct |
17 ms |
4332 KB |
Output is correct |
56 |
Correct |
9 ms |
4332 KB |
Output is correct |
57 |
Correct |
11 ms |
4332 KB |
Output is correct |
58 |
Correct |
11 ms |
4332 KB |
Output is correct |
59 |
Correct |
13 ms |
4332 KB |
Output is correct |
60 |
Correct |
12 ms |
4332 KB |
Output is correct |
61 |
Correct |
12 ms |
4332 KB |
Output is correct |
62 |
Correct |
12 ms |
4332 KB |
Output is correct |
63 |
Correct |
13 ms |
4332 KB |
Output is correct |
64 |
Correct |
16 ms |
4332 KB |
Output is correct |
65 |
Correct |
10 ms |
4332 KB |
Output is correct |
66 |
Correct |
10 ms |
4332 KB |
Output is correct |
67 |
Correct |
11 ms |
4332 KB |
Output is correct |
68 |
Correct |
14 ms |
4332 KB |
Output is correct |
69 |
Correct |
15 ms |
4332 KB |
Output is correct |
70 |
Correct |
16 ms |
4332 KB |
Output is correct |
71 |
Correct |
13 ms |
4332 KB |
Output is correct |
72 |
Correct |
16 ms |
4332 KB |
Output is correct |
73 |
Correct |
13 ms |
4332 KB |
Output is correct |
74 |
Correct |
14 ms |
4332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4352 KB |
Output is correct |
2 |
Correct |
8 ms |
4332 KB |
Output is correct |
3 |
Correct |
8 ms |
4332 KB |
Output is correct |
4 |
Correct |
10 ms |
4332 KB |
Output is correct |
5 |
Correct |
10 ms |
4332 KB |
Output is correct |
6 |
Correct |
10 ms |
4332 KB |
Output is correct |
7 |
Correct |
9 ms |
4332 KB |
Output is correct |
8 |
Correct |
11 ms |
4332 KB |
Output is correct |
9 |
Correct |
10 ms |
4332 KB |
Output is correct |
10 |
Correct |
9 ms |
4332 KB |
Output is correct |
11 |
Correct |
10 ms |
4332 KB |
Output is correct |
12 |
Correct |
9 ms |
4236 KB |
Output is correct |
13 |
Correct |
10 ms |
4332 KB |
Output is correct |
14 |
Correct |
9 ms |
4332 KB |
Output is correct |
15 |
Correct |
9 ms |
4332 KB |
Output is correct |
16 |
Correct |
10 ms |
4460 KB |
Output is correct |
17 |
Correct |
9 ms |
4332 KB |
Output is correct |
18 |
Correct |
9 ms |
4332 KB |
Output is correct |
19 |
Correct |
9 ms |
4332 KB |
Output is correct |
20 |
Correct |
9 ms |
4332 KB |
Output is correct |
21 |
Correct |
9 ms |
4332 KB |
Output is correct |
22 |
Correct |
9 ms |
4332 KB |
Output is correct |
23 |
Correct |
9 ms |
4332 KB |
Output is correct |
24 |
Correct |
9 ms |
4332 KB |
Output is correct |
25 |
Correct |
9 ms |
4332 KB |
Output is correct |
26 |
Correct |
10 ms |
4332 KB |
Output is correct |
27 |
Correct |
14 ms |
4332 KB |
Output is correct |
28 |
Correct |
10 ms |
4332 KB |
Output is correct |
29 |
Correct |
11 ms |
4332 KB |
Output is correct |
30 |
Correct |
11 ms |
4332 KB |
Output is correct |
31 |
Correct |
11 ms |
4332 KB |
Output is correct |
32 |
Correct |
11 ms |
4332 KB |
Output is correct |
33 |
Correct |
10 ms |
4332 KB |
Output is correct |
34 |
Correct |
10 ms |
4332 KB |
Output is correct |
35 |
Correct |
11 ms |
4332 KB |
Output is correct |
36 |
Correct |
15 ms |
4332 KB |
Output is correct |
37 |
Correct |
15 ms |
4332 KB |
Output is correct |
38 |
Correct |
17 ms |
4332 KB |
Output is correct |
39 |
Correct |
17 ms |
4332 KB |
Output is correct |
40 |
Correct |
18 ms |
4332 KB |
Output is correct |
41 |
Correct |
17 ms |
4332 KB |
Output is correct |
42 |
Correct |
18 ms |
4332 KB |
Output is correct |
43 |
Correct |
9 ms |
4332 KB |
Output is correct |
44 |
Correct |
12 ms |
4332 KB |
Output is correct |
45 |
Correct |
13 ms |
4332 KB |
Output is correct |
46 |
Correct |
12 ms |
4332 KB |
Output is correct |
47 |
Correct |
11 ms |
4332 KB |
Output is correct |
48 |
Correct |
12 ms |
4332 KB |
Output is correct |
49 |
Correct |
12 ms |
4332 KB |
Output is correct |
50 |
Correct |
16 ms |
4332 KB |
Output is correct |
51 |
Correct |
13 ms |
4332 KB |
Output is correct |
52 |
Correct |
6 ms |
364 KB |
Output is correct |
53 |
Correct |
5 ms |
364 KB |
Output is correct |
54 |
Correct |
22 ms |
364 KB |
Output is correct |
55 |
Correct |
14 ms |
364 KB |
Output is correct |
56 |
Correct |
31 ms |
364 KB |
Output is correct |
57 |
Correct |
24 ms |
364 KB |
Output is correct |
58 |
Correct |
37 ms |
364 KB |
Output is correct |
59 |
Correct |
66 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
15 ms |
4332 KB |
Output is correct |
62 |
Correct |
4 ms |
364 KB |
Output is correct |
63 |
Correct |
23 ms |
364 KB |
Output is correct |
64 |
Correct |
7 ms |
364 KB |
Output is correct |
65 |
Correct |
13 ms |
364 KB |
Output is correct |
66 |
Correct |
21 ms |
364 KB |
Output is correct |
67 |
Correct |
1 ms |
364 KB |
Output is correct |
68 |
Correct |
87 ms |
364 KB |
Output is correct |
69 |
Correct |
24 ms |
364 KB |
Output is correct |