#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > PII;
#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define y1 kekek
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
const ll ool = 1e18 + 9;
const int N = 2e3 + 6, oo = 1e9 + 9, base = 1e9 + 7;
int n, A, B, a[N], d[N][N], d2[N];
ll ans = ool;
bool bit[22];
bool check(ll mask1, ll mask2, int pos) {
mask1 >>= 1ll * pos;
mask2 >>= 1ll * pos;
return ((mask1 | mask2) == mask1);
}
bool calc(ll mask, int pos) {
d[0][0] = 1;
forn(i, 1, n) {
forn(j, 1, B) {
d[i][j] = 0;
ll sum = 0;
for1(k, i, 1) {
sum += a[k];
if (!check(mask, sum, pos)) continue;
d[i][j] |= d[k - 1][j - 1];
}
}
}
forn(i, A, B) {
if (d[n][i]) return 1;
}
return 0;
}
bool calc2(ll mask, int pos) {
d2[0] = 0;
forn(i, 1, n) {
d2[i] = oo;
ll sum = 0;
for1(k, i, 1) {
sum += a[k];
if (!check(mask, sum, pos)) continue;
d2[i] = min(d2[i], d2[k - 1] + 1);
}
}
return (d2[n] <= B);
}
int main() {
#ifdef krauch
freopen("input.txt", "r", stdin);
#endif
cin >> n >> A >> B;
forn(i, 1, n) {
cin >> a[i];
}
ll ans = 0;
for1(i, 41, 0) {
ans |= (1ll << i);
bool res = (A == 1 ? calc2(ans, i) : calc(ans, i));
ans ^= (1ll << i);
if (!res) ans |= (1ll << (i + 1));
}
bool res = (A == 1 ? calc2(ans, 0) : calc(ans, 0));
if (!res) ans++;
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
404 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
2 ms |
480 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
2 ms |
480 KB |
Output is correct |
9 |
Correct |
2 ms |
480 KB |
Output is correct |
10 |
Correct |
2 ms |
660 KB |
Output is correct |
11 |
Correct |
1 ms |
660 KB |
Output is correct |
12 |
Correct |
1 ms |
660 KB |
Output is correct |
13 |
Correct |
2 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
1 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
732 KB |
Output is correct |
21 |
Correct |
2 ms |
732 KB |
Output is correct |
22 |
Correct |
2 ms |
732 KB |
Output is correct |
23 |
Correct |
2 ms |
732 KB |
Output is correct |
24 |
Correct |
2 ms |
732 KB |
Output is correct |
25 |
Correct |
2 ms |
732 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
1 ms |
732 KB |
Output is correct |
28 |
Correct |
2 ms |
732 KB |
Output is correct |
29 |
Correct |
2 ms |
732 KB |
Output is correct |
30 |
Correct |
2 ms |
732 KB |
Output is correct |
31 |
Correct |
2 ms |
732 KB |
Output is correct |
32 |
Correct |
1 ms |
732 KB |
Output is correct |
33 |
Correct |
1 ms |
732 KB |
Output is correct |
34 |
Correct |
1 ms |
732 KB |
Output is correct |
35 |
Correct |
1 ms |
732 KB |
Output is correct |
36 |
Correct |
1 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
732 KB |
Output is correct |
2 |
Correct |
2 ms |
732 KB |
Output is correct |
3 |
Correct |
2 ms |
732 KB |
Output is correct |
4 |
Correct |
2 ms |
732 KB |
Output is correct |
5 |
Correct |
1 ms |
732 KB |
Output is correct |
6 |
Correct |
2 ms |
732 KB |
Output is correct |
7 |
Correct |
2 ms |
732 KB |
Output is correct |
8 |
Correct |
1 ms |
732 KB |
Output is correct |
9 |
Correct |
2 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
732 KB |
Output is correct |
12 |
Correct |
1 ms |
732 KB |
Output is correct |
13 |
Correct |
2 ms |
732 KB |
Output is correct |
14 |
Correct |
1 ms |
732 KB |
Output is correct |
15 |
Correct |
1 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
1 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
732 KB |
Output is correct |
21 |
Correct |
2 ms |
732 KB |
Output is correct |
22 |
Correct |
2 ms |
732 KB |
Output is correct |
23 |
Correct |
2 ms |
732 KB |
Output is correct |
24 |
Correct |
2 ms |
732 KB |
Output is correct |
25 |
Correct |
2 ms |
732 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
1 ms |
732 KB |
Output is correct |
28 |
Correct |
2 ms |
732 KB |
Output is correct |
29 |
Correct |
2 ms |
732 KB |
Output is correct |
30 |
Correct |
2 ms |
732 KB |
Output is correct |
31 |
Correct |
2 ms |
732 KB |
Output is correct |
32 |
Correct |
2 ms |
732 KB |
Output is correct |
33 |
Correct |
2 ms |
732 KB |
Output is correct |
34 |
Correct |
2 ms |
732 KB |
Output is correct |
35 |
Correct |
2 ms |
732 KB |
Output is correct |
36 |
Correct |
2 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
732 KB |
Output is correct |
2 |
Correct |
2 ms |
732 KB |
Output is correct |
3 |
Correct |
2 ms |
732 KB |
Output is correct |
4 |
Correct |
1 ms |
732 KB |
Output is correct |
5 |
Correct |
2 ms |
732 KB |
Output is correct |
6 |
Correct |
2 ms |
732 KB |
Output is correct |
7 |
Correct |
2 ms |
732 KB |
Output is correct |
8 |
Correct |
1 ms |
744 KB |
Output is correct |
9 |
Correct |
2 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
744 KB |
Output is correct |
11 |
Correct |
1 ms |
744 KB |
Output is correct |
12 |
Correct |
2 ms |
744 KB |
Output is correct |
13 |
Correct |
2 ms |
744 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
1 ms |
744 KB |
Output is correct |
16 |
Correct |
2 ms |
744 KB |
Output is correct |
17 |
Correct |
2 ms |
744 KB |
Output is correct |
18 |
Correct |
2 ms |
744 KB |
Output is correct |
19 |
Correct |
2 ms |
744 KB |
Output is correct |
20 |
Correct |
2 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
744 KB |
Output is correct |
22 |
Correct |
2 ms |
744 KB |
Output is correct |
23 |
Correct |
2 ms |
744 KB |
Output is correct |
24 |
Correct |
2 ms |
744 KB |
Output is correct |
25 |
Correct |
2 ms |
744 KB |
Output is correct |
26 |
Correct |
2 ms |
744 KB |
Output is correct |
27 |
Correct |
3 ms |
744 KB |
Output is correct |
28 |
Correct |
2 ms |
744 KB |
Output is correct |
29 |
Correct |
2 ms |
744 KB |
Output is correct |
30 |
Correct |
2 ms |
744 KB |
Output is correct |
31 |
Correct |
2 ms |
744 KB |
Output is correct |
32 |
Correct |
2 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
744 KB |
Output is correct |
2 |
Correct |
1 ms |
744 KB |
Output is correct |
3 |
Correct |
2 ms |
744 KB |
Output is correct |
4 |
Correct |
2 ms |
744 KB |
Output is correct |
5 |
Correct |
2 ms |
744 KB |
Output is correct |
6 |
Correct |
1 ms |
744 KB |
Output is correct |
7 |
Correct |
1 ms |
744 KB |
Output is correct |
8 |
Correct |
1 ms |
744 KB |
Output is correct |
9 |
Correct |
2 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
744 KB |
Output is correct |
11 |
Correct |
1 ms |
744 KB |
Output is correct |
12 |
Correct |
2 ms |
744 KB |
Output is correct |
13 |
Correct |
1 ms |
744 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
2 ms |
744 KB |
Output is correct |
16 |
Correct |
1 ms |
744 KB |
Output is correct |
17 |
Correct |
1 ms |
744 KB |
Output is correct |
18 |
Correct |
2 ms |
744 KB |
Output is correct |
19 |
Correct |
2 ms |
744 KB |
Output is correct |
20 |
Correct |
2 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
744 KB |
Output is correct |
22 |
Correct |
2 ms |
744 KB |
Output is correct |
23 |
Correct |
2 ms |
744 KB |
Output is correct |
24 |
Correct |
2 ms |
744 KB |
Output is correct |
25 |
Correct |
2 ms |
744 KB |
Output is correct |
26 |
Correct |
2 ms |
744 KB |
Output is correct |
27 |
Correct |
2 ms |
744 KB |
Output is correct |
28 |
Correct |
2 ms |
744 KB |
Output is correct |
29 |
Correct |
2 ms |
744 KB |
Output is correct |
30 |
Correct |
2 ms |
744 KB |
Output is correct |
31 |
Correct |
2 ms |
744 KB |
Output is correct |
32 |
Correct |
2 ms |
744 KB |
Output is correct |
33 |
Correct |
2 ms |
744 KB |
Output is correct |
34 |
Correct |
1 ms |
744 KB |
Output is correct |
35 |
Correct |
2 ms |
744 KB |
Output is correct |
36 |
Correct |
2 ms |
744 KB |
Output is correct |
37 |
Correct |
2 ms |
744 KB |
Output is correct |
38 |
Correct |
2 ms |
744 KB |
Output is correct |
39 |
Correct |
2 ms |
744 KB |
Output is correct |
40 |
Correct |
2 ms |
744 KB |
Output is correct |
41 |
Correct |
2 ms |
744 KB |
Output is correct |
42 |
Correct |
2 ms |
744 KB |
Output is correct |
43 |
Correct |
2 ms |
744 KB |
Output is correct |
44 |
Correct |
2 ms |
744 KB |
Output is correct |
45 |
Correct |
2 ms |
744 KB |
Output is correct |
46 |
Correct |
1 ms |
744 KB |
Output is correct |
47 |
Correct |
2 ms |
744 KB |
Output is correct |
48 |
Correct |
2 ms |
744 KB |
Output is correct |
49 |
Correct |
3 ms |
744 KB |
Output is correct |
50 |
Correct |
2 ms |
744 KB |
Output is correct |
51 |
Correct |
3 ms |
744 KB |
Output is correct |
52 |
Correct |
2 ms |
744 KB |
Output is correct |
53 |
Correct |
3 ms |
744 KB |
Output is correct |
54 |
Correct |
3 ms |
744 KB |
Output is correct |
55 |
Correct |
2 ms |
744 KB |
Output is correct |
56 |
Correct |
2 ms |
744 KB |
Output is correct |
57 |
Correct |
2 ms |
744 KB |
Output is correct |
58 |
Correct |
2 ms |
744 KB |
Output is correct |
59 |
Correct |
3 ms |
744 KB |
Output is correct |
60 |
Correct |
3 ms |
744 KB |
Output is correct |
61 |
Correct |
2 ms |
744 KB |
Output is correct |
62 |
Correct |
2 ms |
744 KB |
Output is correct |
63 |
Correct |
2 ms |
744 KB |
Output is correct |
64 |
Correct |
45 ms |
1004 KB |
Output is correct |
65 |
Correct |
4 ms |
1004 KB |
Output is correct |
66 |
Correct |
4 ms |
1004 KB |
Output is correct |
67 |
Correct |
8 ms |
1004 KB |
Output is correct |
68 |
Correct |
23 ms |
1004 KB |
Output is correct |
69 |
Correct |
47 ms |
1132 KB |
Output is correct |
70 |
Correct |
45 ms |
1132 KB |
Output is correct |
71 |
Correct |
3 ms |
1132 KB |
Output is correct |
72 |
Correct |
48 ms |
1132 KB |
Output is correct |
73 |
Correct |
39 ms |
1132 KB |
Output is correct |
74 |
Correct |
33 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1132 KB |
Output is correct |
2 |
Correct |
1 ms |
1132 KB |
Output is correct |
3 |
Correct |
2 ms |
1132 KB |
Output is correct |
4 |
Correct |
2 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
2 ms |
1132 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
11 |
Correct |
2 ms |
1132 KB |
Output is correct |
12 |
Correct |
2 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1132 KB |
Output is correct |
14 |
Correct |
2 ms |
1132 KB |
Output is correct |
15 |
Correct |
1 ms |
1132 KB |
Output is correct |
16 |
Correct |
2 ms |
1132 KB |
Output is correct |
17 |
Correct |
2 ms |
1132 KB |
Output is correct |
18 |
Correct |
1 ms |
1132 KB |
Output is correct |
19 |
Correct |
1 ms |
1132 KB |
Output is correct |
20 |
Correct |
2 ms |
1132 KB |
Output is correct |
21 |
Correct |
1 ms |
1132 KB |
Output is correct |
22 |
Correct |
2 ms |
1132 KB |
Output is correct |
23 |
Correct |
2 ms |
1132 KB |
Output is correct |
24 |
Correct |
2 ms |
1132 KB |
Output is correct |
25 |
Correct |
2 ms |
1132 KB |
Output is correct |
26 |
Correct |
2 ms |
1132 KB |
Output is correct |
27 |
Correct |
2 ms |
1132 KB |
Output is correct |
28 |
Correct |
2 ms |
1132 KB |
Output is correct |
29 |
Correct |
2 ms |
1132 KB |
Output is correct |
30 |
Correct |
2 ms |
1132 KB |
Output is correct |
31 |
Correct |
2 ms |
1132 KB |
Output is correct |
32 |
Correct |
2 ms |
1132 KB |
Output is correct |
33 |
Correct |
2 ms |
1132 KB |
Output is correct |
34 |
Correct |
2 ms |
1132 KB |
Output is correct |
35 |
Correct |
2 ms |
1132 KB |
Output is correct |
36 |
Correct |
2 ms |
1132 KB |
Output is correct |
37 |
Correct |
3 ms |
1132 KB |
Output is correct |
38 |
Correct |
2 ms |
1132 KB |
Output is correct |
39 |
Correct |
2 ms |
1132 KB |
Output is correct |
40 |
Correct |
2 ms |
1132 KB |
Output is correct |
41 |
Correct |
2 ms |
1132 KB |
Output is correct |
42 |
Correct |
2 ms |
1132 KB |
Output is correct |
43 |
Correct |
2 ms |
1132 KB |
Output is correct |
44 |
Correct |
2 ms |
1132 KB |
Output is correct |
45 |
Correct |
2 ms |
1132 KB |
Output is correct |
46 |
Correct |
2 ms |
1132 KB |
Output is correct |
47 |
Correct |
2 ms |
1132 KB |
Output is correct |
48 |
Correct |
2 ms |
1132 KB |
Output is correct |
49 |
Correct |
2 ms |
1132 KB |
Output is correct |
50 |
Correct |
2 ms |
1132 KB |
Output is correct |
51 |
Correct |
2 ms |
1132 KB |
Output is correct |
52 |
Correct |
16 ms |
1132 KB |
Output is correct |
53 |
Correct |
25 ms |
1132 KB |
Output is correct |
54 |
Correct |
45 ms |
1132 KB |
Output is correct |
55 |
Correct |
43 ms |
1132 KB |
Output is correct |
56 |
Correct |
161 ms |
1132 KB |
Output is correct |
57 |
Correct |
156 ms |
1132 KB |
Output is correct |
58 |
Correct |
158 ms |
1132 KB |
Output is correct |
59 |
Correct |
151 ms |
1132 KB |
Output is correct |
60 |
Correct |
168 ms |
1132 KB |
Output is correct |
61 |
Correct |
2 ms |
1132 KB |
Output is correct |
62 |
Correct |
25 ms |
1132 KB |
Output is correct |
63 |
Correct |
45 ms |
1132 KB |
Output is correct |
64 |
Correct |
48 ms |
1132 KB |
Output is correct |
65 |
Correct |
80 ms |
1132 KB |
Output is correct |
66 |
Correct |
121 ms |
1132 KB |
Output is correct |
67 |
Correct |
163 ms |
1132 KB |
Output is correct |
68 |
Correct |
167 ms |
1132 KB |
Output is correct |
69 |
Correct |
157 ms |
1132 KB |
Output is correct |