#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, A, B;
long long Y[2001];
bool dp[2001][2001];
int dp2[2001];
bool solve(long long X) {
//cout<<bitset<41>(X)<<"\n";
if (A == 1) {
rep(i, N+1) dp2[i] = INF;
dp2[0] = 0;
for (int x=0; x<N; x++) {
if (dp2[x] == INF) continue;
for (int t=x+1; t<=N; t++) {
if (((Y[t]-Y[x]) | X) == X) dp2[t] = min(dp2[t], dp2[x]+1);
}
}
return dp2[N] <= B;
}
else {
rep(i, N+1) rep(j, N+1) dp[i][j] = 0;
dp[0][0] = true;
bool f = false;
for (int x=0; x<N; x++) {
rep(num, x+1) {
if (!dp[x][num]) continue;
for (int t=x+1; t<=N; t++) {
if (((Y[t]-Y[x]) | X) == X) dp[t][num+1] = true;
}
}
}
for (int i=A; i<=B; i++) f |= dp[N][i];
return f;
}
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> A >> B;
rep(i, N) cin >> Y[i+1], Y[i+1] += Y[i];
long long X = 0;
for (int i=40; i>=0; i--) {
if (!solve(X | ((1LL<<i)-1))) X |= 1LL<<i;
}
cout << X << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6108 KB |
Output is correct |
2 |
Correct |
0 ms |
6108 KB |
Output is correct |
3 |
Correct |
0 ms |
6108 KB |
Output is correct |
4 |
Correct |
0 ms |
6108 KB |
Output is correct |
5 |
Correct |
0 ms |
6108 KB |
Output is correct |
6 |
Correct |
0 ms |
6108 KB |
Output is correct |
7 |
Correct |
0 ms |
6108 KB |
Output is correct |
8 |
Correct |
0 ms |
6108 KB |
Output is correct |
9 |
Correct |
0 ms |
6108 KB |
Output is correct |
10 |
Correct |
0 ms |
6108 KB |
Output is correct |
11 |
Correct |
0 ms |
6108 KB |
Output is correct |
12 |
Correct |
0 ms |
6108 KB |
Output is correct |
13 |
Correct |
0 ms |
6108 KB |
Output is correct |
14 |
Correct |
0 ms |
6108 KB |
Output is correct |
15 |
Correct |
0 ms |
6108 KB |
Output is correct |
16 |
Correct |
0 ms |
6108 KB |
Output is correct |
17 |
Correct |
0 ms |
6108 KB |
Output is correct |
18 |
Correct |
0 ms |
6108 KB |
Output is correct |
19 |
Correct |
0 ms |
6108 KB |
Output is correct |
20 |
Correct |
0 ms |
6108 KB |
Output is correct |
21 |
Correct |
0 ms |
6108 KB |
Output is correct |
22 |
Correct |
0 ms |
6108 KB |
Output is correct |
23 |
Correct |
0 ms |
6108 KB |
Output is correct |
24 |
Correct |
0 ms |
6108 KB |
Output is correct |
25 |
Correct |
0 ms |
6108 KB |
Output is correct |
26 |
Correct |
0 ms |
6108 KB |
Output is correct |
27 |
Correct |
0 ms |
6108 KB |
Output is correct |
28 |
Correct |
0 ms |
6108 KB |
Output is correct |
29 |
Correct |
0 ms |
6108 KB |
Output is correct |
30 |
Correct |
0 ms |
6108 KB |
Output is correct |
31 |
Correct |
0 ms |
6108 KB |
Output is correct |
32 |
Correct |
0 ms |
6108 KB |
Output is correct |
33 |
Correct |
0 ms |
6108 KB |
Output is correct |
34 |
Correct |
0 ms |
6108 KB |
Output is correct |
35 |
Correct |
0 ms |
6108 KB |
Output is correct |
36 |
Correct |
0 ms |
6108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6108 KB |
Output is correct |
2 |
Correct |
0 ms |
6108 KB |
Output is correct |
3 |
Correct |
0 ms |
6108 KB |
Output is correct |
4 |
Correct |
0 ms |
6108 KB |
Output is correct |
5 |
Correct |
0 ms |
6108 KB |
Output is correct |
6 |
Correct |
0 ms |
6108 KB |
Output is correct |
7 |
Correct |
0 ms |
6108 KB |
Output is correct |
8 |
Correct |
0 ms |
6108 KB |
Output is correct |
9 |
Correct |
0 ms |
6108 KB |
Output is correct |
10 |
Correct |
0 ms |
6108 KB |
Output is correct |
11 |
Correct |
0 ms |
6108 KB |
Output is correct |
12 |
Correct |
0 ms |
6108 KB |
Output is correct |
13 |
Correct |
0 ms |
6108 KB |
Output is correct |
14 |
Correct |
0 ms |
6108 KB |
Output is correct |
15 |
Correct |
0 ms |
6108 KB |
Output is correct |
16 |
Correct |
0 ms |
6108 KB |
Output is correct |
17 |
Correct |
0 ms |
6108 KB |
Output is correct |
18 |
Correct |
0 ms |
6108 KB |
Output is correct |
19 |
Correct |
0 ms |
6108 KB |
Output is correct |
20 |
Correct |
0 ms |
6108 KB |
Output is correct |
21 |
Correct |
0 ms |
6108 KB |
Output is correct |
22 |
Correct |
0 ms |
6108 KB |
Output is correct |
23 |
Correct |
0 ms |
6108 KB |
Output is correct |
24 |
Correct |
0 ms |
6108 KB |
Output is correct |
25 |
Correct |
0 ms |
6108 KB |
Output is correct |
26 |
Correct |
0 ms |
6108 KB |
Output is correct |
27 |
Correct |
0 ms |
6108 KB |
Output is correct |
28 |
Correct |
0 ms |
6108 KB |
Output is correct |
29 |
Correct |
0 ms |
6108 KB |
Output is correct |
30 |
Correct |
0 ms |
6108 KB |
Output is correct |
31 |
Correct |
0 ms |
6108 KB |
Output is correct |
32 |
Correct |
0 ms |
6108 KB |
Output is correct |
33 |
Correct |
0 ms |
6108 KB |
Output is correct |
34 |
Correct |
0 ms |
6108 KB |
Output is correct |
35 |
Correct |
0 ms |
6108 KB |
Output is correct |
36 |
Correct |
0 ms |
6108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6108 KB |
Output is correct |
2 |
Correct |
0 ms |
6108 KB |
Output is correct |
3 |
Correct |
0 ms |
6108 KB |
Output is correct |
4 |
Correct |
0 ms |
6108 KB |
Output is correct |
5 |
Correct |
0 ms |
6108 KB |
Output is correct |
6 |
Correct |
0 ms |
6108 KB |
Output is correct |
7 |
Correct |
0 ms |
6108 KB |
Output is correct |
8 |
Correct |
0 ms |
6108 KB |
Output is correct |
9 |
Correct |
0 ms |
6108 KB |
Output is correct |
10 |
Correct |
0 ms |
6108 KB |
Output is correct |
11 |
Correct |
0 ms |
6108 KB |
Output is correct |
12 |
Correct |
0 ms |
6108 KB |
Output is correct |
13 |
Correct |
0 ms |
6108 KB |
Output is correct |
14 |
Correct |
0 ms |
6108 KB |
Output is correct |
15 |
Correct |
0 ms |
6108 KB |
Output is correct |
16 |
Correct |
0 ms |
6108 KB |
Output is correct |
17 |
Correct |
0 ms |
6108 KB |
Output is correct |
18 |
Correct |
0 ms |
6108 KB |
Output is correct |
19 |
Correct |
0 ms |
6108 KB |
Output is correct |
20 |
Correct |
0 ms |
6108 KB |
Output is correct |
21 |
Correct |
0 ms |
6108 KB |
Output is correct |
22 |
Correct |
0 ms |
6108 KB |
Output is correct |
23 |
Correct |
0 ms |
6108 KB |
Output is correct |
24 |
Correct |
0 ms |
6108 KB |
Output is correct |
25 |
Correct |
0 ms |
6108 KB |
Output is correct |
26 |
Correct |
0 ms |
6108 KB |
Output is correct |
27 |
Correct |
0 ms |
6108 KB |
Output is correct |
28 |
Correct |
0 ms |
6108 KB |
Output is correct |
29 |
Correct |
0 ms |
6108 KB |
Output is correct |
30 |
Correct |
0 ms |
6108 KB |
Output is correct |
31 |
Correct |
0 ms |
6108 KB |
Output is correct |
32 |
Correct |
0 ms |
6108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6108 KB |
Output is correct |
2 |
Correct |
0 ms |
6108 KB |
Output is correct |
3 |
Correct |
0 ms |
6108 KB |
Output is correct |
4 |
Correct |
0 ms |
6108 KB |
Output is correct |
5 |
Correct |
0 ms |
6108 KB |
Output is correct |
6 |
Correct |
0 ms |
6108 KB |
Output is correct |
7 |
Correct |
0 ms |
6108 KB |
Output is correct |
8 |
Correct |
0 ms |
6108 KB |
Output is correct |
9 |
Correct |
0 ms |
6108 KB |
Output is correct |
10 |
Correct |
0 ms |
6108 KB |
Output is correct |
11 |
Correct |
0 ms |
6108 KB |
Output is correct |
12 |
Correct |
0 ms |
6108 KB |
Output is correct |
13 |
Correct |
0 ms |
6108 KB |
Output is correct |
14 |
Correct |
0 ms |
6108 KB |
Output is correct |
15 |
Correct |
0 ms |
6108 KB |
Output is correct |
16 |
Correct |
0 ms |
6108 KB |
Output is correct |
17 |
Correct |
0 ms |
6108 KB |
Output is correct |
18 |
Correct |
0 ms |
6108 KB |
Output is correct |
19 |
Correct |
0 ms |
6108 KB |
Output is correct |
20 |
Correct |
0 ms |
6108 KB |
Output is correct |
21 |
Correct |
0 ms |
6108 KB |
Output is correct |
22 |
Correct |
0 ms |
6108 KB |
Output is correct |
23 |
Correct |
0 ms |
6108 KB |
Output is correct |
24 |
Correct |
0 ms |
6108 KB |
Output is correct |
25 |
Correct |
0 ms |
6108 KB |
Output is correct |
26 |
Correct |
0 ms |
6108 KB |
Output is correct |
27 |
Correct |
0 ms |
6108 KB |
Output is correct |
28 |
Correct |
0 ms |
6108 KB |
Output is correct |
29 |
Correct |
0 ms |
6108 KB |
Output is correct |
30 |
Correct |
0 ms |
6108 KB |
Output is correct |
31 |
Correct |
0 ms |
6108 KB |
Output is correct |
32 |
Correct |
0 ms |
6108 KB |
Output is correct |
33 |
Correct |
0 ms |
6108 KB |
Output is correct |
34 |
Correct |
0 ms |
6108 KB |
Output is correct |
35 |
Correct |
0 ms |
6108 KB |
Output is correct |
36 |
Correct |
0 ms |
6108 KB |
Output is correct |
37 |
Correct |
0 ms |
6108 KB |
Output is correct |
38 |
Correct |
0 ms |
6108 KB |
Output is correct |
39 |
Correct |
0 ms |
6108 KB |
Output is correct |
40 |
Correct |
0 ms |
6108 KB |
Output is correct |
41 |
Correct |
0 ms |
6108 KB |
Output is correct |
42 |
Correct |
0 ms |
6108 KB |
Output is correct |
43 |
Correct |
0 ms |
6108 KB |
Output is correct |
44 |
Correct |
0 ms |
6108 KB |
Output is correct |
45 |
Correct |
0 ms |
6108 KB |
Output is correct |
46 |
Correct |
0 ms |
6108 KB |
Output is correct |
47 |
Correct |
0 ms |
6108 KB |
Output is correct |
48 |
Correct |
0 ms |
6108 KB |
Output is correct |
49 |
Correct |
0 ms |
6108 KB |
Output is correct |
50 |
Correct |
0 ms |
6108 KB |
Output is correct |
51 |
Correct |
0 ms |
6108 KB |
Output is correct |
52 |
Correct |
0 ms |
6108 KB |
Output is correct |
53 |
Correct |
0 ms |
6108 KB |
Output is correct |
54 |
Correct |
0 ms |
6108 KB |
Output is correct |
55 |
Correct |
0 ms |
6108 KB |
Output is correct |
56 |
Correct |
0 ms |
6108 KB |
Output is correct |
57 |
Correct |
0 ms |
6108 KB |
Output is correct |
58 |
Correct |
0 ms |
6108 KB |
Output is correct |
59 |
Correct |
0 ms |
6108 KB |
Output is correct |
60 |
Correct |
0 ms |
6108 KB |
Output is correct |
61 |
Correct |
0 ms |
6108 KB |
Output is correct |
62 |
Correct |
0 ms |
6108 KB |
Output is correct |
63 |
Correct |
0 ms |
6108 KB |
Output is correct |
64 |
Correct |
6 ms |
6108 KB |
Output is correct |
65 |
Correct |
0 ms |
6108 KB |
Output is correct |
66 |
Correct |
0 ms |
6108 KB |
Output is correct |
67 |
Correct |
0 ms |
6108 KB |
Output is correct |
68 |
Correct |
3 ms |
6108 KB |
Output is correct |
69 |
Correct |
3 ms |
6108 KB |
Output is correct |
70 |
Correct |
3 ms |
6108 KB |
Output is correct |
71 |
Correct |
3 ms |
6108 KB |
Output is correct |
72 |
Correct |
3 ms |
6108 KB |
Output is correct |
73 |
Correct |
3 ms |
6108 KB |
Output is correct |
74 |
Correct |
3 ms |
6108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6108 KB |
Output is correct |
2 |
Correct |
0 ms |
6108 KB |
Output is correct |
3 |
Correct |
0 ms |
6108 KB |
Output is correct |
4 |
Correct |
0 ms |
6108 KB |
Output is correct |
5 |
Correct |
0 ms |
6108 KB |
Output is correct |
6 |
Correct |
0 ms |
6108 KB |
Output is correct |
7 |
Correct |
0 ms |
6108 KB |
Output is correct |
8 |
Correct |
0 ms |
6108 KB |
Output is correct |
9 |
Correct |
0 ms |
6108 KB |
Output is correct |
10 |
Correct |
0 ms |
6108 KB |
Output is correct |
11 |
Correct |
0 ms |
6108 KB |
Output is correct |
12 |
Correct |
0 ms |
6108 KB |
Output is correct |
13 |
Correct |
0 ms |
6108 KB |
Output is correct |
14 |
Correct |
0 ms |
6108 KB |
Output is correct |
15 |
Correct |
0 ms |
6108 KB |
Output is correct |
16 |
Correct |
0 ms |
6108 KB |
Output is correct |
17 |
Correct |
0 ms |
6108 KB |
Output is correct |
18 |
Correct |
0 ms |
6108 KB |
Output is correct |
19 |
Correct |
0 ms |
6108 KB |
Output is correct |
20 |
Correct |
0 ms |
6108 KB |
Output is correct |
21 |
Correct |
0 ms |
6108 KB |
Output is correct |
22 |
Correct |
0 ms |
6108 KB |
Output is correct |
23 |
Correct |
0 ms |
6108 KB |
Output is correct |
24 |
Correct |
0 ms |
6108 KB |
Output is correct |
25 |
Correct |
0 ms |
6108 KB |
Output is correct |
26 |
Correct |
0 ms |
6108 KB |
Output is correct |
27 |
Correct |
0 ms |
6108 KB |
Output is correct |
28 |
Correct |
0 ms |
6108 KB |
Output is correct |
29 |
Correct |
0 ms |
6108 KB |
Output is correct |
30 |
Correct |
0 ms |
6108 KB |
Output is correct |
31 |
Correct |
0 ms |
6108 KB |
Output is correct |
32 |
Correct |
0 ms |
6108 KB |
Output is correct |
33 |
Correct |
0 ms |
6108 KB |
Output is correct |
34 |
Correct |
0 ms |
6108 KB |
Output is correct |
35 |
Correct |
0 ms |
6108 KB |
Output is correct |
36 |
Correct |
0 ms |
6108 KB |
Output is correct |
37 |
Correct |
0 ms |
6108 KB |
Output is correct |
38 |
Correct |
0 ms |
6108 KB |
Output is correct |
39 |
Correct |
0 ms |
6108 KB |
Output is correct |
40 |
Correct |
0 ms |
6108 KB |
Output is correct |
41 |
Correct |
0 ms |
6108 KB |
Output is correct |
42 |
Correct |
0 ms |
6108 KB |
Output is correct |
43 |
Correct |
0 ms |
6108 KB |
Output is correct |
44 |
Correct |
0 ms |
6108 KB |
Output is correct |
45 |
Correct |
0 ms |
6108 KB |
Output is correct |
46 |
Correct |
0 ms |
6108 KB |
Output is correct |
47 |
Correct |
0 ms |
6108 KB |
Output is correct |
48 |
Correct |
0 ms |
6108 KB |
Output is correct |
49 |
Correct |
0 ms |
6108 KB |
Output is correct |
50 |
Correct |
0 ms |
6108 KB |
Output is correct |
51 |
Correct |
0 ms |
6108 KB |
Output is correct |
52 |
Correct |
3 ms |
6108 KB |
Output is correct |
53 |
Correct |
6 ms |
6108 KB |
Output is correct |
54 |
Correct |
29 ms |
6108 KB |
Output is correct |
55 |
Correct |
13 ms |
6108 KB |
Output is correct |
56 |
Correct |
29 ms |
6108 KB |
Output is correct |
57 |
Correct |
23 ms |
6108 KB |
Output is correct |
58 |
Correct |
36 ms |
6108 KB |
Output is correct |
59 |
Correct |
53 ms |
6108 KB |
Output is correct |
60 |
Correct |
33 ms |
6108 KB |
Output is correct |
61 |
Correct |
0 ms |
6108 KB |
Output is correct |
62 |
Correct |
3 ms |
6108 KB |
Output is correct |
63 |
Correct |
23 ms |
6108 KB |
Output is correct |
64 |
Correct |
6 ms |
6108 KB |
Output is correct |
65 |
Correct |
16 ms |
6108 KB |
Output is correct |
66 |
Correct |
23 ms |
6108 KB |
Output is correct |
67 |
Correct |
36 ms |
6108 KB |
Output is correct |
68 |
Correct |
89 ms |
6108 KB |
Output is correct |
69 |
Correct |
23 ms |
6108 KB |
Output is correct |