#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 2020
#define MAXS 20
#define INF 1'000'000'100'000'000'000
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 998244353
#define TC 1
ll arr[MAX];
ll S[MAX];
ll dp[MAX][MAX];
int dis[MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, A, B;
cin >> N >> A >> B;
int i, j, k;
for (i = 1; i <= N; i++) cin >> arr[i], S[i] = S[i - 1] + arr[i];
for (i = 0; i < MAX; i++) for (j = 0; j < MAX; j++) dp[i][j] = INF;
if (A > 1) {
for (i = 1; i <= N; i++) {
for (j = 1; j < i; j++) for (k = 1; k <= j; k++) dp[i][k + 1] = min(dp[i][k + 1], dp[j][k] | (S[i] - S[j]));
dp[i][1] = S[i];
}
ll ans = INF;
for (i = A; i <= B; i++) ans = min(ans, dp[N][i]);
cout << ans << ln;
return 0;
}
ll mask = 0;
for (i = 50; i >= 0; i--) {
ll nmask = mask | (1ll << i);
for (j = 1; j <= N; j++) dis[j] = N + 100;
for (j = 0; j <= N; j++) {
if (dis[j] > N) continue;
for (k = j + 1; k <= N; k++) {
if ((S[k] - S[j]) & nmask) continue;
dis[k] = min(dis[k], dis[j] + 1);
}
}
if (dis[N] <= B) mask = nmask;
}
mask ^= ((1ll << 51) - 1);
cout << mask << ln;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
32344 KB |
Output is correct |
2 |
Correct |
6 ms |
32344 KB |
Output is correct |
3 |
Correct |
6 ms |
32344 KB |
Output is correct |
4 |
Correct |
7 ms |
32344 KB |
Output is correct |
5 |
Correct |
6 ms |
32344 KB |
Output is correct |
6 |
Correct |
6 ms |
32600 KB |
Output is correct |
7 |
Correct |
6 ms |
32344 KB |
Output is correct |
8 |
Correct |
6 ms |
32348 KB |
Output is correct |
9 |
Correct |
6 ms |
32344 KB |
Output is correct |
10 |
Correct |
6 ms |
32344 KB |
Output is correct |
11 |
Correct |
6 ms |
32344 KB |
Output is correct |
12 |
Correct |
6 ms |
32344 KB |
Output is correct |
13 |
Correct |
6 ms |
32344 KB |
Output is correct |
14 |
Correct |
6 ms |
32344 KB |
Output is correct |
15 |
Correct |
6 ms |
32344 KB |
Output is correct |
16 |
Correct |
6 ms |
32344 KB |
Output is correct |
17 |
Correct |
6 ms |
32344 KB |
Output is correct |
18 |
Correct |
6 ms |
32344 KB |
Output is correct |
19 |
Correct |
6 ms |
32344 KB |
Output is correct |
20 |
Correct |
6 ms |
32344 KB |
Output is correct |
21 |
Incorrect |
6 ms |
32344 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
32344 KB |
Output is correct |
2 |
Correct |
6 ms |
32600 KB |
Output is correct |
3 |
Correct |
6 ms |
32344 KB |
Output is correct |
4 |
Correct |
7 ms |
32348 KB |
Output is correct |
5 |
Correct |
6 ms |
32348 KB |
Output is correct |
6 |
Correct |
7 ms |
32344 KB |
Output is correct |
7 |
Correct |
6 ms |
32348 KB |
Output is correct |
8 |
Correct |
6 ms |
32344 KB |
Output is correct |
9 |
Correct |
6 ms |
32344 KB |
Output is correct |
10 |
Correct |
6 ms |
32344 KB |
Output is correct |
11 |
Correct |
6 ms |
32344 KB |
Output is correct |
12 |
Correct |
6 ms |
32344 KB |
Output is correct |
13 |
Correct |
6 ms |
32344 KB |
Output is correct |
14 |
Correct |
6 ms |
32344 KB |
Output is correct |
15 |
Correct |
7 ms |
32344 KB |
Output is correct |
16 |
Correct |
6 ms |
32344 KB |
Output is correct |
17 |
Correct |
6 ms |
32348 KB |
Output is correct |
18 |
Correct |
6 ms |
32344 KB |
Output is correct |
19 |
Correct |
6 ms |
32344 KB |
Output is correct |
20 |
Correct |
6 ms |
32348 KB |
Output is correct |
21 |
Incorrect |
6 ms |
32344 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
32344 KB |
Output is correct |
2 |
Correct |
6 ms |
32168 KB |
Output is correct |
3 |
Correct |
6 ms |
32344 KB |
Output is correct |
4 |
Correct |
6 ms |
32348 KB |
Output is correct |
5 |
Correct |
6 ms |
32344 KB |
Output is correct |
6 |
Correct |
6 ms |
32344 KB |
Output is correct |
7 |
Correct |
6 ms |
32344 KB |
Output is correct |
8 |
Correct |
7 ms |
32348 KB |
Output is correct |
9 |
Correct |
7 ms |
32344 KB |
Output is correct |
10 |
Correct |
6 ms |
32344 KB |
Output is correct |
11 |
Correct |
6 ms |
32344 KB |
Output is correct |
12 |
Correct |
6 ms |
32344 KB |
Output is correct |
13 |
Correct |
6 ms |
32344 KB |
Output is correct |
14 |
Correct |
6 ms |
32348 KB |
Output is correct |
15 |
Correct |
6 ms |
32344 KB |
Output is correct |
16 |
Correct |
6 ms |
32348 KB |
Output is correct |
17 |
Correct |
7 ms |
32344 KB |
Output is correct |
18 |
Correct |
7 ms |
32600 KB |
Output is correct |
19 |
Correct |
6 ms |
32344 KB |
Output is correct |
20 |
Correct |
6 ms |
32344 KB |
Output is correct |
21 |
Correct |
6 ms |
32344 KB |
Output is correct |
22 |
Correct |
6 ms |
32344 KB |
Output is correct |
23 |
Correct |
6 ms |
32344 KB |
Output is correct |
24 |
Correct |
6 ms |
32348 KB |
Output is correct |
25 |
Correct |
6 ms |
32344 KB |
Output is correct |
26 |
Correct |
6 ms |
32344 KB |
Output is correct |
27 |
Correct |
6 ms |
32348 KB |
Output is correct |
28 |
Correct |
7 ms |
32348 KB |
Output is correct |
29 |
Correct |
6 ms |
32344 KB |
Output is correct |
30 |
Correct |
7 ms |
32344 KB |
Output is correct |
31 |
Correct |
6 ms |
32344 KB |
Output is correct |
32 |
Correct |
7 ms |
32344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
32344 KB |
Output is correct |
2 |
Correct |
6 ms |
32344 KB |
Output is correct |
3 |
Correct |
6 ms |
32344 KB |
Output is correct |
4 |
Correct |
6 ms |
32348 KB |
Output is correct |
5 |
Correct |
6 ms |
32344 KB |
Output is correct |
6 |
Correct |
7 ms |
32344 KB |
Output is correct |
7 |
Correct |
6 ms |
32544 KB |
Output is correct |
8 |
Correct |
6 ms |
32344 KB |
Output is correct |
9 |
Correct |
6 ms |
32344 KB |
Output is correct |
10 |
Correct |
6 ms |
32344 KB |
Output is correct |
11 |
Correct |
6 ms |
32344 KB |
Output is correct |
12 |
Correct |
6 ms |
32344 KB |
Output is correct |
13 |
Correct |
6 ms |
32344 KB |
Output is correct |
14 |
Correct |
6 ms |
32344 KB |
Output is correct |
15 |
Correct |
6 ms |
32344 KB |
Output is correct |
16 |
Correct |
6 ms |
32344 KB |
Output is correct |
17 |
Correct |
6 ms |
32344 KB |
Output is correct |
18 |
Correct |
6 ms |
32344 KB |
Output is correct |
19 |
Correct |
6 ms |
32344 KB |
Output is correct |
20 |
Correct |
7 ms |
32348 KB |
Output is correct |
21 |
Incorrect |
7 ms |
32344 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
32344 KB |
Output is correct |
2 |
Correct |
6 ms |
32344 KB |
Output is correct |
3 |
Correct |
7 ms |
32344 KB |
Output is correct |
4 |
Correct |
6 ms |
32344 KB |
Output is correct |
5 |
Correct |
6 ms |
32344 KB |
Output is correct |
6 |
Correct |
6 ms |
32344 KB |
Output is correct |
7 |
Correct |
6 ms |
32344 KB |
Output is correct |
8 |
Correct |
6 ms |
32344 KB |
Output is correct |
9 |
Correct |
6 ms |
32344 KB |
Output is correct |
10 |
Correct |
7 ms |
32600 KB |
Output is correct |
11 |
Correct |
7 ms |
32344 KB |
Output is correct |
12 |
Correct |
6 ms |
32348 KB |
Output is correct |
13 |
Correct |
7 ms |
32344 KB |
Output is correct |
14 |
Correct |
6 ms |
32344 KB |
Output is correct |
15 |
Correct |
6 ms |
32348 KB |
Output is correct |
16 |
Correct |
6 ms |
32348 KB |
Output is correct |
17 |
Correct |
6 ms |
32344 KB |
Output is correct |
18 |
Correct |
6 ms |
32344 KB |
Output is correct |
19 |
Correct |
6 ms |
32344 KB |
Output is correct |
20 |
Correct |
7 ms |
32348 KB |
Output is correct |
21 |
Correct |
6 ms |
32344 KB |
Output is correct |
22 |
Correct |
6 ms |
32344 KB |
Output is correct |
23 |
Correct |
6 ms |
32344 KB |
Output is correct |
24 |
Correct |
6 ms |
32344 KB |
Output is correct |
25 |
Correct |
6 ms |
32344 KB |
Output is correct |
26 |
Correct |
6 ms |
32344 KB |
Output is correct |
27 |
Correct |
7 ms |
32348 KB |
Output is correct |
28 |
Correct |
7 ms |
32348 KB |
Output is correct |
29 |
Correct |
7 ms |
32600 KB |
Output is correct |
30 |
Correct |
7 ms |
32344 KB |
Output is correct |
31 |
Correct |
7 ms |
32348 KB |
Output is correct |
32 |
Correct |
6 ms |
32344 KB |
Output is correct |
33 |
Correct |
7 ms |
32348 KB |
Output is correct |
34 |
Correct |
8 ms |
32600 KB |
Output is correct |
35 |
Correct |
7 ms |
32344 KB |
Output is correct |
36 |
Correct |
7 ms |
32344 KB |
Output is correct |
37 |
Correct |
8 ms |
32348 KB |
Output is correct |
38 |
Correct |
6 ms |
32344 KB |
Output is correct |
39 |
Correct |
6 ms |
32348 KB |
Output is correct |
40 |
Correct |
6 ms |
32180 KB |
Output is correct |
41 |
Correct |
7 ms |
32344 KB |
Output is correct |
42 |
Correct |
7 ms |
32344 KB |
Output is correct |
43 |
Correct |
7 ms |
32600 KB |
Output is correct |
44 |
Correct |
6 ms |
32344 KB |
Output is correct |
45 |
Correct |
6 ms |
32344 KB |
Output is correct |
46 |
Correct |
6 ms |
32344 KB |
Output is correct |
47 |
Correct |
7 ms |
32348 KB |
Output is correct |
48 |
Correct |
7 ms |
32344 KB |
Output is correct |
49 |
Correct |
6 ms |
32344 KB |
Output is correct |
50 |
Correct |
6 ms |
32344 KB |
Output is correct |
51 |
Correct |
7 ms |
32208 KB |
Output is correct |
52 |
Correct |
13 ms |
32344 KB |
Output is correct |
53 |
Correct |
15 ms |
32344 KB |
Output is correct |
54 |
Correct |
29 ms |
32344 KB |
Output is correct |
55 |
Correct |
24 ms |
32344 KB |
Output is correct |
56 |
Correct |
58 ms |
32344 KB |
Output is correct |
57 |
Correct |
56 ms |
32344 KB |
Output is correct |
58 |
Correct |
61 ms |
32344 KB |
Output is correct |
59 |
Correct |
73 ms |
32344 KB |
Output is correct |
60 |
Correct |
62 ms |
32348 KB |
Output is correct |
61 |
Correct |
6 ms |
32344 KB |
Output is correct |
62 |
Correct |
14 ms |
32344 KB |
Output is correct |
63 |
Correct |
30 ms |
32344 KB |
Output is correct |
64 |
Correct |
19 ms |
32344 KB |
Output is correct |
65 |
Correct |
31 ms |
32344 KB |
Output is correct |
66 |
Correct |
43 ms |
32460 KB |
Output is correct |
67 |
Correct |
55 ms |
32348 KB |
Output is correct |
68 |
Correct |
92 ms |
32344 KB |
Output is correct |
69 |
Correct |
56 ms |
32344 KB |
Output is correct |