// Muallif: Azimjon Mehmonali o'g'li
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = (1ll << 35) - 1;
const int N = 2111;
const int K = 2111;
int n, k, a, b;
int y[N], p[N], dp[K][N], pp[N];
bool check(int mask, int cand) { return (!(~mask & cand)); }
bool can(int mask) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
dp[0][i] = check(mask, p[i]);
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
dp[k][i] |= dp[k - 1][j] && check(mask, p[i] - p[j]);
}
}
}
bool fl = 0;
for (int i = a; i <= b; i++) {
fl |= dp[i - 1][n];
}
return fl;
}
bool cann(int mask) {
for (int i = 0; i < N; i++)
pp[i] = INF;
pp[1] = 0;
for (int i = 1; i <= n; i++) {
if (pp[i] >= INF) continue;
for (int j = i; j <= n; j++) {
if (check(mask, p[j] - p[i - 1])) {
pp[j + 1] = min(pp[j + 1], pp[i] + 1);
}
}
}
return pp[n + 1] <= b;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> y[i];
p[i] = p[i - 1] + y[i];
}
int nt = (1ll << 51) - 1;
for (int i = 50; i >= 0; i--) {
if (a == 1) {
if (cann(nt - (1ll << i))) {
nt -= (1ll << i);
}
} else {
if (can(nt - (1ll << i))) {
nt -= (1ll << i);
}
}
}
cout << nt << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 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 |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
324 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 |
241 ms |
35192 KB |
Output is correct |
15 |
Correct |
244 ms |
35208 KB |
Output is correct |
16 |
Correct |
255 ms |
35280 KB |
Output is correct |
17 |
Correct |
249 ms |
35156 KB |
Output is correct |
18 |
Correct |
245 ms |
35204 KB |
Output is correct |
19 |
Correct |
249 ms |
35188 KB |
Output is correct |
20 |
Correct |
240 ms |
35204 KB |
Output is correct |
21 |
Correct |
246 ms |
35188 KB |
Output is correct |
22 |
Correct |
249 ms |
35172 KB |
Output is correct |
23 |
Correct |
251 ms |
35148 KB |
Output is correct |
24 |
Correct |
256 ms |
35192 KB |
Output is correct |
25 |
Correct |
239 ms |
35148 KB |
Output is correct |
26 |
Correct |
243 ms |
35204 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 |
320 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 |
328 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 |
324 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 |
243 ms |
35148 KB |
Output is correct |
15 |
Correct |
248 ms |
35148 KB |
Output is correct |
16 |
Correct |
249 ms |
35140 KB |
Output is correct |
17 |
Correct |
244 ms |
35148 KB |
Output is correct |
18 |
Correct |
252 ms |
35200 KB |
Output is correct |
19 |
Correct |
244 ms |
35196 KB |
Output is correct |
20 |
Correct |
249 ms |
35184 KB |
Output is correct |
21 |
Correct |
249 ms |
35148 KB |
Output is correct |
22 |
Correct |
241 ms |
35136 KB |
Output is correct |
23 |
Correct |
252 ms |
35148 KB |
Output is correct |
24 |
Correct |
250 ms |
35188 KB |
Output is correct |
25 |
Correct |
240 ms |
35196 KB |
Output is correct |
26 |
Correct |
246 ms |
35164 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 |
336 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 |
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 |
324 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 |
348 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 |
328 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 |
2 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 |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
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 |
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 |
320 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 |
250 ms |
35196 KB |
Output is correct |
15 |
Correct |
253 ms |
35140 KB |
Output is correct |
16 |
Correct |
251 ms |
35148 KB |
Output is correct |
17 |
Correct |
245 ms |
35136 KB |
Output is correct |
18 |
Correct |
249 ms |
35260 KB |
Output is correct |
19 |
Correct |
249 ms |
35192 KB |
Output is correct |
20 |
Correct |
252 ms |
35148 KB |
Output is correct |
21 |
Correct |
243 ms |
35268 KB |
Output is correct |
22 |
Correct |
250 ms |
35192 KB |
Output is correct |
23 |
Correct |
254 ms |
35148 KB |
Output is correct |
24 |
Correct |
249 ms |
35192 KB |
Output is correct |
25 |
Correct |
239 ms |
35148 KB |
Output is correct |
26 |
Correct |
247 ms |
35192 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
324 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 |
328 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 |
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 |
324 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 |
328 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 |
332 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
268 ms |
35268 KB |
Output is correct |
65 |
Correct |
255 ms |
35188 KB |
Output is correct |
66 |
Correct |
254 ms |
35204 KB |
Output is correct |
67 |
Correct |
268 ms |
35148 KB |
Output is correct |
68 |
Correct |
268 ms |
35200 KB |
Output is correct |
69 |
Correct |
275 ms |
35148 KB |
Output is correct |
70 |
Correct |
274 ms |
35148 KB |
Output is correct |
71 |
Correct |
284 ms |
35192 KB |
Output is correct |
72 |
Correct |
289 ms |
35192 KB |
Output is correct |
73 |
Correct |
274 ms |
35188 KB |
Output is correct |
74 |
Correct |
284 ms |
35196 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 |
320 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 |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
324 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 |
336 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 |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
320 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
320 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 |
320 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 |
324 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
328 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 |
332 KB |
Output is correct |
52 |
Correct |
8 ms |
332 KB |
Output is correct |
53 |
Correct |
8 ms |
332 KB |
Output is correct |
54 |
Correct |
29 ms |
332 KB |
Output is correct |
55 |
Correct |
23 ms |
332 KB |
Output is correct |
56 |
Correct |
68 ms |
332 KB |
Output is correct |
57 |
Correct |
49 ms |
332 KB |
Output is correct |
58 |
Correct |
62 ms |
332 KB |
Output is correct |
59 |
Correct |
86 ms |
376 KB |
Output is correct |
60 |
Correct |
59 ms |
376 KB |
Output is correct |
61 |
Correct |
1 ms |
332 KB |
Output is correct |
62 |
Correct |
10 ms |
332 KB |
Output is correct |
63 |
Correct |
38 ms |
332 KB |
Output is correct |
64 |
Correct |
13 ms |
376 KB |
Output is correct |
65 |
Correct |
32 ms |
332 KB |
Output is correct |
66 |
Correct |
37 ms |
460 KB |
Output is correct |
67 |
Correct |
54 ms |
384 KB |
Output is correct |
68 |
Correct |
135 ms |
332 KB |
Output is correct |
69 |
Correct |
63 ms |
332 KB |
Output is correct |