#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define fastInp ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long
using namespace std;
const int MAXN = 2005;
const int INF = 1e18;
int y[MAXN];
int pref[MAXN];
int n, a, b;
int get_sum(int l, int r) {
return pref[r] - pref[l - 1];
}
bool in(int small, int big) {
return ((big & small) == small);
}
namespace subtask4 {
bool dp[MAXN][MAXN];
bool check(int x) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int gr = 1; gr <= b; gr++) {
for (int i = gr; i <= n; i++) {
for (int last = 0; last < i; last++) {
if (dp[gr - 1][last] && in(get_sum(last + 1, i), x)) {
dp[gr][i] = 1;
}
}
}
}
for (int gr = a; gr <= b; gr++) {
if (dp[gr][n]) {
return true;
}
}
return false;
}
void solve() {
int cur = (1ll << 63) - 1;
for (int i = 62; i >= 0; i--) {
if (check(cur ^ (1ll << i))) {
cur ^= (1ll << i);
}
}
cout << cur << endl;
exit(0);
}
};
signed main() {
fastInp;
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> y[i];
pref[i] = pref[i - 1] + y[i];
}
if (a > 1) {
subtask4::solve();
} else {
auto check = [&](int x) {
vector <int> dp(MAXN, INF);
dp[0] = 0;
for (int i = 0; i < n; i++) {
if (dp[i] == INF) {
continue;
}
for (int j = i + 1; j <= n; j++) {
if (in(get_sum(i + 1, j), x)) {
dp[j] = min(dp[j], dp[i] + 1);
}
}
}
return dp[n] <= b;
};
int cur = (1ll << 63) - 1;
for (int i = 62; i >= 0; i--) {
if (check(cur ^ (1ll << i))) {
cur ^= (1ll << i);
}
}
cout << cur << endl;
}
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message
sculpture.cpp: In function 'void subtask4::solve()':
sculpture.cpp:48:25: warning: integer overflow in expression of type 'long long int' results in '9223372036854775807' [-Woverflow]
48 | int cur = (1ll << 63) - 1;
| ~~~~~~~~~~~~^~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:84:25: warning: integer overflow in expression of type 'long long int' results in '9223372036854775807' [-Woverflow]
84 | int cur = (1ll << 63) - 1;
| ~~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
11 ms |
4256 KB |
Output is correct |
15 |
Correct |
11 ms |
4172 KB |
Output is correct |
16 |
Correct |
12 ms |
4256 KB |
Output is correct |
17 |
Correct |
12 ms |
4256 KB |
Output is correct |
18 |
Correct |
12 ms |
4172 KB |
Output is correct |
19 |
Correct |
12 ms |
4172 KB |
Output is correct |
20 |
Correct |
12 ms |
4172 KB |
Output is correct |
21 |
Correct |
12 ms |
4172 KB |
Output is correct |
22 |
Correct |
13 ms |
4256 KB |
Output is correct |
23 |
Correct |
13 ms |
4252 KB |
Output is correct |
24 |
Correct |
12 ms |
4252 KB |
Output is correct |
25 |
Correct |
11 ms |
4172 KB |
Output is correct |
26 |
Correct |
12 ms |
4256 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
12 ms |
4252 KB |
Output is correct |
15 |
Correct |
12 ms |
4256 KB |
Output is correct |
16 |
Correct |
12 ms |
4172 KB |
Output is correct |
17 |
Correct |
13 ms |
4260 KB |
Output is correct |
18 |
Correct |
11 ms |
4172 KB |
Output is correct |
19 |
Correct |
12 ms |
4172 KB |
Output is correct |
20 |
Correct |
12 ms |
4172 KB |
Output is correct |
21 |
Correct |
12 ms |
4172 KB |
Output is correct |
22 |
Correct |
12 ms |
4256 KB |
Output is correct |
23 |
Correct |
11 ms |
4172 KB |
Output is correct |
24 |
Correct |
12 ms |
4256 KB |
Output is correct |
25 |
Correct |
12 ms |
4172 KB |
Output is correct |
26 |
Correct |
12 ms |
4172 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
11 ms |
4172 KB |
Output is correct |
15 |
Correct |
11 ms |
4264 KB |
Output is correct |
16 |
Correct |
12 ms |
4300 KB |
Output is correct |
17 |
Correct |
12 ms |
4256 KB |
Output is correct |
18 |
Correct |
11 ms |
4172 KB |
Output is correct |
19 |
Correct |
12 ms |
4256 KB |
Output is correct |
20 |
Correct |
12 ms |
4252 KB |
Output is correct |
21 |
Correct |
13 ms |
4172 KB |
Output is correct |
22 |
Correct |
11 ms |
4252 KB |
Output is correct |
23 |
Correct |
11 ms |
4172 KB |
Output is correct |
24 |
Correct |
12 ms |
4252 KB |
Output is correct |
25 |
Correct |
12 ms |
4172 KB |
Output is correct |
26 |
Correct |
12 ms |
4252 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
1 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
332 KB |
Output is correct |
56 |
Correct |
1 ms |
332 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
1 ms |
336 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
32 ms |
4172 KB |
Output is correct |
65 |
Correct |
14 ms |
4256 KB |
Output is correct |
66 |
Correct |
14 ms |
4172 KB |
Output is correct |
67 |
Correct |
17 ms |
4260 KB |
Output is correct |
68 |
Correct |
31 ms |
4256 KB |
Output is correct |
69 |
Correct |
39 ms |
4172 KB |
Output is correct |
70 |
Correct |
40 ms |
4172 KB |
Output is correct |
71 |
Correct |
12 ms |
4172 KB |
Output is correct |
72 |
Correct |
41 ms |
4256 KB |
Output is correct |
73 |
Correct |
37 ms |
4172 KB |
Output is correct |
74 |
Correct |
35 ms |
4260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
280 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
13 ms |
332 KB |
Output is correct |
53 |
Correct |
14 ms |
376 KB |
Output is correct |
54 |
Correct |
47 ms |
336 KB |
Output is correct |
55 |
Correct |
36 ms |
332 KB |
Output is correct |
56 |
Correct |
103 ms |
332 KB |
Output is correct |
57 |
Correct |
96 ms |
332 KB |
Output is correct |
58 |
Correct |
118 ms |
340 KB |
Output is correct |
59 |
Correct |
152 ms |
452 KB |
Output is correct |
60 |
Correct |
109 ms |
376 KB |
Output is correct |
61 |
Correct |
1 ms |
324 KB |
Output is correct |
62 |
Correct |
14 ms |
332 KB |
Output is correct |
63 |
Correct |
48 ms |
332 KB |
Output is correct |
64 |
Correct |
25 ms |
332 KB |
Output is correct |
65 |
Correct |
50 ms |
376 KB |
Output is correct |
66 |
Correct |
78 ms |
332 KB |
Output is correct |
67 |
Correct |
97 ms |
332 KB |
Output is correct |
68 |
Correct |
190 ms |
332 KB |
Output is correct |
69 |
Correct |
103 ms |
332 KB |
Output is correct |