#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 get_sum(int l, int r) {
return pref[r] - pref[l - 1];
}
bool dp[MAXN][MAXN];
int n, a, b;
bool in(int small, int big) {
return ((big & small) == small);
}
// можно использовать только биты в x
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;
}
signed main() {
fastInp;
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> y[i];
pref[i] = pref[i - 1] + y[i];
}
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 'int main()':
sculpture.cpp:58:24: warning: integer overflow in expression of type 'long long int' results in '9223372036854775807' [-Woverflow]
58 | int cur = (1ll << 63) - 1;
| ~~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
4256 KB |
Output is correct |
2 |
Correct |
12 ms |
4172 KB |
Output is correct |
3 |
Correct |
12 ms |
4168 KB |
Output is correct |
4 |
Correct |
11 ms |
4172 KB |
Output is correct |
5 |
Correct |
12 ms |
4172 KB |
Output is correct |
6 |
Correct |
12 ms |
4260 KB |
Output is correct |
7 |
Correct |
12 ms |
4172 KB |
Output is correct |
8 |
Correct |
12 ms |
4172 KB |
Output is correct |
9 |
Correct |
12 ms |
4172 KB |
Output is correct |
10 |
Correct |
13 ms |
4172 KB |
Output is correct |
11 |
Correct |
13 ms |
4256 KB |
Output is correct |
12 |
Correct |
12 ms |
4264 KB |
Output is correct |
13 |
Correct |
12 ms |
4172 KB |
Output is correct |
14 |
Correct |
14 ms |
4168 KB |
Output is correct |
15 |
Correct |
12 ms |
4264 KB |
Output is correct |
16 |
Correct |
12 ms |
4172 KB |
Output is correct |
17 |
Correct |
12 ms |
4172 KB |
Output is correct |
18 |
Correct |
12 ms |
4260 KB |
Output is correct |
19 |
Correct |
12 ms |
4260 KB |
Output is correct |
20 |
Correct |
12 ms |
4264 KB |
Output is correct |
21 |
Correct |
12 ms |
4260 KB |
Output is correct |
22 |
Correct |
12 ms |
4260 KB |
Output is correct |
23 |
Correct |
12 ms |
4172 KB |
Output is correct |
24 |
Correct |
12 ms |
4172 KB |
Output is correct |
25 |
Correct |
12 ms |
4260 KB |
Output is correct |
26 |
Correct |
12 ms |
4172 KB |
Output is correct |
27 |
Correct |
12 ms |
4260 KB |
Output is correct |
28 |
Correct |
12 ms |
4172 KB |
Output is correct |
29 |
Correct |
12 ms |
4172 KB |
Output is correct |
30 |
Correct |
12 ms |
4172 KB |
Output is correct |
31 |
Correct |
12 ms |
4172 KB |
Output is correct |
32 |
Correct |
12 ms |
4264 KB |
Output is correct |
33 |
Correct |
14 ms |
4264 KB |
Output is correct |
34 |
Correct |
12 ms |
4260 KB |
Output is correct |
35 |
Correct |
12 ms |
4264 KB |
Output is correct |
36 |
Correct |
12 ms |
4260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
4172 KB |
Output is correct |
2 |
Correct |
12 ms |
4256 KB |
Output is correct |
3 |
Correct |
11 ms |
4172 KB |
Output is correct |
4 |
Correct |
12 ms |
4176 KB |
Output is correct |
5 |
Correct |
12 ms |
4168 KB |
Output is correct |
6 |
Correct |
12 ms |
4172 KB |
Output is correct |
7 |
Correct |
12 ms |
4172 KB |
Output is correct |
8 |
Correct |
12 ms |
4172 KB |
Output is correct |
9 |
Correct |
14 ms |
4252 KB |
Output is correct |
10 |
Correct |
13 ms |
4172 KB |
Output is correct |
11 |
Correct |
12 ms |
4260 KB |
Output is correct |
12 |
Correct |
12 ms |
4260 KB |
Output is correct |
13 |
Correct |
12 ms |
4256 KB |
Output is correct |
14 |
Correct |
12 ms |
4256 KB |
Output is correct |
15 |
Correct |
12 ms |
4172 KB |
Output is correct |
16 |
Correct |
11 ms |
4260 KB |
Output is correct |
17 |
Correct |
13 ms |
4256 KB |
Output is correct |
18 |
Correct |
12 ms |
4256 KB |
Output is correct |
19 |
Correct |
12 ms |
4172 KB |
Output is correct |
20 |
Correct |
12 ms |
4264 KB |
Output is correct |
21 |
Correct |
12 ms |
4172 KB |
Output is correct |
22 |
Correct |
12 ms |
4172 KB |
Output is correct |
23 |
Correct |
12 ms |
4224 KB |
Output is correct |
24 |
Correct |
12 ms |
4264 KB |
Output is correct |
25 |
Correct |
14 ms |
4260 KB |
Output is correct |
26 |
Correct |
13 ms |
4256 KB |
Output is correct |
27 |
Correct |
12 ms |
4260 KB |
Output is correct |
28 |
Correct |
13 ms |
4260 KB |
Output is correct |
29 |
Correct |
12 ms |
4164 KB |
Output is correct |
30 |
Correct |
13 ms |
4172 KB |
Output is correct |
31 |
Correct |
16 ms |
4172 KB |
Output is correct |
32 |
Correct |
16 ms |
4172 KB |
Output is correct |
33 |
Correct |
12 ms |
4260 KB |
Output is correct |
34 |
Correct |
14 ms |
4260 KB |
Output is correct |
35 |
Correct |
14 ms |
4172 KB |
Output is correct |
36 |
Correct |
13 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
4260 KB |
Output is correct |
2 |
Correct |
12 ms |
4172 KB |
Output is correct |
3 |
Correct |
13 ms |
4172 KB |
Output is correct |
4 |
Correct |
12 ms |
4264 KB |
Output is correct |
5 |
Correct |
12 ms |
4260 KB |
Output is correct |
6 |
Correct |
12 ms |
4172 KB |
Output is correct |
7 |
Correct |
13 ms |
4260 KB |
Output is correct |
8 |
Correct |
12 ms |
4180 KB |
Output is correct |
9 |
Correct |
13 ms |
4168 KB |
Output is correct |
10 |
Correct |
14 ms |
4260 KB |
Output is correct |
11 |
Correct |
12 ms |
4172 KB |
Output is correct |
12 |
Correct |
12 ms |
4256 KB |
Output is correct |
13 |
Correct |
12 ms |
4172 KB |
Output is correct |
14 |
Correct |
12 ms |
4172 KB |
Output is correct |
15 |
Correct |
12 ms |
4172 KB |
Output is correct |
16 |
Correct |
12 ms |
4172 KB |
Output is correct |
17 |
Correct |
14 ms |
4172 KB |
Output is correct |
18 |
Correct |
20 ms |
4172 KB |
Output is correct |
19 |
Correct |
14 ms |
4172 KB |
Output is correct |
20 |
Correct |
12 ms |
4172 KB |
Output is correct |
21 |
Correct |
14 ms |
4172 KB |
Output is correct |
22 |
Correct |
17 ms |
4164 KB |
Output is correct |
23 |
Correct |
15 ms |
4172 KB |
Output is correct |
24 |
Correct |
15 ms |
4260 KB |
Output is correct |
25 |
Correct |
17 ms |
4168 KB |
Output is correct |
26 |
Correct |
18 ms |
4172 KB |
Output is correct |
27 |
Correct |
30 ms |
4168 KB |
Output is correct |
28 |
Correct |
41 ms |
4172 KB |
Output is correct |
29 |
Correct |
40 ms |
4172 KB |
Output is correct |
30 |
Correct |
12 ms |
4260 KB |
Output is correct |
31 |
Correct |
31 ms |
4180 KB |
Output is correct |
32 |
Correct |
38 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
4264 KB |
Output is correct |
2 |
Correct |
12 ms |
4264 KB |
Output is correct |
3 |
Correct |
12 ms |
4260 KB |
Output is correct |
4 |
Correct |
14 ms |
4180 KB |
Output is correct |
5 |
Correct |
12 ms |
4268 KB |
Output is correct |
6 |
Correct |
12 ms |
4180 KB |
Output is correct |
7 |
Correct |
12 ms |
4172 KB |
Output is correct |
8 |
Correct |
11 ms |
4172 KB |
Output is correct |
9 |
Correct |
13 ms |
4264 KB |
Output is correct |
10 |
Correct |
12 ms |
4260 KB |
Output is correct |
11 |
Correct |
12 ms |
4260 KB |
Output is correct |
12 |
Correct |
12 ms |
4260 KB |
Output is correct |
13 |
Correct |
12 ms |
4260 KB |
Output is correct |
14 |
Correct |
12 ms |
4172 KB |
Output is correct |
15 |
Correct |
12 ms |
4172 KB |
Output is correct |
16 |
Correct |
12 ms |
4172 KB |
Output is correct |
17 |
Correct |
12 ms |
4176 KB |
Output is correct |
18 |
Correct |
13 ms |
4256 KB |
Output is correct |
19 |
Correct |
17 ms |
4296 KB |
Output is correct |
20 |
Correct |
12 ms |
4260 KB |
Output is correct |
21 |
Correct |
12 ms |
4172 KB |
Output is correct |
22 |
Correct |
12 ms |
4172 KB |
Output is correct |
23 |
Correct |
12 ms |
4260 KB |
Output is correct |
24 |
Correct |
12 ms |
4260 KB |
Output is correct |
25 |
Correct |
12 ms |
4260 KB |
Output is correct |
26 |
Correct |
12 ms |
4256 KB |
Output is correct |
27 |
Correct |
12 ms |
4260 KB |
Output is correct |
28 |
Correct |
11 ms |
4172 KB |
Output is correct |
29 |
Correct |
12 ms |
4260 KB |
Output is correct |
30 |
Correct |
12 ms |
4176 KB |
Output is correct |
31 |
Correct |
12 ms |
4260 KB |
Output is correct |
32 |
Correct |
11 ms |
4260 KB |
Output is correct |
33 |
Correct |
13 ms |
4172 KB |
Output is correct |
34 |
Correct |
12 ms |
4172 KB |
Output is correct |
35 |
Correct |
12 ms |
4264 KB |
Output is correct |
36 |
Correct |
12 ms |
4172 KB |
Output is correct |
37 |
Correct |
12 ms |
4172 KB |
Output is correct |
38 |
Correct |
13 ms |
4172 KB |
Output is correct |
39 |
Correct |
13 ms |
4264 KB |
Output is correct |
40 |
Correct |
14 ms |
4172 KB |
Output is correct |
41 |
Correct |
14 ms |
4240 KB |
Output is correct |
42 |
Correct |
15 ms |
4144 KB |
Output is correct |
43 |
Correct |
12 ms |
4164 KB |
Output is correct |
44 |
Correct |
15 ms |
4144 KB |
Output is correct |
45 |
Correct |
14 ms |
4260 KB |
Output is correct |
46 |
Correct |
13 ms |
4172 KB |
Output is correct |
47 |
Correct |
14 ms |
4260 KB |
Output is correct |
48 |
Correct |
14 ms |
4172 KB |
Output is correct |
49 |
Correct |
20 ms |
4260 KB |
Output is correct |
50 |
Correct |
30 ms |
4252 KB |
Output is correct |
51 |
Correct |
40 ms |
4172 KB |
Output is correct |
52 |
Correct |
41 ms |
4172 KB |
Output is correct |
53 |
Correct |
12 ms |
4172 KB |
Output is correct |
54 |
Correct |
32 ms |
4172 KB |
Output is correct |
55 |
Correct |
39 ms |
4256 KB |
Output is correct |
56 |
Correct |
15 ms |
4300 KB |
Output is correct |
57 |
Correct |
19 ms |
4268 KB |
Output is correct |
58 |
Correct |
29 ms |
4264 KB |
Output is correct |
59 |
Correct |
38 ms |
4172 KB |
Output is correct |
60 |
Correct |
42 ms |
4172 KB |
Output is correct |
61 |
Correct |
16 ms |
4268 KB |
Output is correct |
62 |
Correct |
42 ms |
4244 KB |
Output is correct |
63 |
Correct |
42 ms |
4172 KB |
Output is correct |
64 |
Correct |
35 ms |
4172 KB |
Output is correct |
65 |
Correct |
14 ms |
4256 KB |
Output is correct |
66 |
Correct |
16 ms |
4172 KB |
Output is correct |
67 |
Correct |
18 ms |
4268 KB |
Output is correct |
68 |
Correct |
29 ms |
4172 KB |
Output is correct |
69 |
Correct |
38 ms |
4172 KB |
Output is correct |
70 |
Correct |
40 ms |
4240 KB |
Output is correct |
71 |
Correct |
12 ms |
4172 KB |
Output is correct |
72 |
Correct |
40 ms |
4172 KB |
Output is correct |
73 |
Correct |
38 ms |
4172 KB |
Output is correct |
74 |
Correct |
37 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
4256 KB |
Output is correct |
2 |
Correct |
12 ms |
4256 KB |
Output is correct |
3 |
Correct |
11 ms |
4172 KB |
Output is correct |
4 |
Correct |
12 ms |
4172 KB |
Output is correct |
5 |
Correct |
11 ms |
4172 KB |
Output is correct |
6 |
Correct |
12 ms |
4260 KB |
Output is correct |
7 |
Correct |
12 ms |
4256 KB |
Output is correct |
8 |
Correct |
12 ms |
4172 KB |
Output is correct |
9 |
Correct |
12 ms |
4172 KB |
Output is correct |
10 |
Correct |
12 ms |
4172 KB |
Output is correct |
11 |
Correct |
13 ms |
4172 KB |
Output is correct |
12 |
Correct |
14 ms |
4184 KB |
Output is correct |
13 |
Correct |
13 ms |
4260 KB |
Output is correct |
14 |
Correct |
15 ms |
4256 KB |
Output is correct |
15 |
Correct |
12 ms |
4172 KB |
Output is correct |
16 |
Correct |
12 ms |
4256 KB |
Output is correct |
17 |
Correct |
12 ms |
4172 KB |
Output is correct |
18 |
Correct |
12 ms |
4256 KB |
Output is correct |
19 |
Correct |
12 ms |
4264 KB |
Output is correct |
20 |
Correct |
12 ms |
4264 KB |
Output is correct |
21 |
Correct |
12 ms |
4172 KB |
Output is correct |
22 |
Correct |
12 ms |
4264 KB |
Output is correct |
23 |
Correct |
13 ms |
4264 KB |
Output is correct |
24 |
Correct |
12 ms |
4172 KB |
Output is correct |
25 |
Correct |
12 ms |
4172 KB |
Output is correct |
26 |
Correct |
13 ms |
4172 KB |
Output is correct |
27 |
Correct |
14 ms |
4172 KB |
Output is correct |
28 |
Correct |
14 ms |
4172 KB |
Output is correct |
29 |
Correct |
14 ms |
4164 KB |
Output is correct |
30 |
Correct |
12 ms |
4260 KB |
Output is correct |
31 |
Correct |
15 ms |
4172 KB |
Output is correct |
32 |
Correct |
13 ms |
4172 KB |
Output is correct |
33 |
Correct |
13 ms |
4256 KB |
Output is correct |
34 |
Correct |
14 ms |
4172 KB |
Output is correct |
35 |
Correct |
13 ms |
4264 KB |
Output is correct |
36 |
Correct |
18 ms |
4172 KB |
Output is correct |
37 |
Correct |
30 ms |
4172 KB |
Output is correct |
38 |
Correct |
53 ms |
4172 KB |
Output is correct |
39 |
Correct |
52 ms |
4172 KB |
Output is correct |
40 |
Correct |
12 ms |
4172 KB |
Output is correct |
41 |
Correct |
31 ms |
4172 KB |
Output is correct |
42 |
Correct |
37 ms |
4168 KB |
Output is correct |
43 |
Correct |
14 ms |
4256 KB |
Output is correct |
44 |
Correct |
18 ms |
4260 KB |
Output is correct |
45 |
Correct |
28 ms |
4172 KB |
Output is correct |
46 |
Correct |
38 ms |
4172 KB |
Output is correct |
47 |
Correct |
55 ms |
4164 KB |
Output is correct |
48 |
Correct |
12 ms |
4172 KB |
Output is correct |
49 |
Correct |
40 ms |
4168 KB |
Output is correct |
50 |
Correct |
41 ms |
4172 KB |
Output is correct |
51 |
Correct |
27 ms |
4172 KB |
Output is correct |
52 |
Execution timed out |
1086 ms |
4172 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |