#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef string str;
const int N = 101;
const int R = 101;
const int Y = 2001;
const ll inf = 1e18;
ll y[N], pref[N];
bool dp[N][R][Y];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
if (n <= 20) {
ll ans = inf;
for (int i = 0; i < n; ++i) {
cin >> y[i];
}
for (int mask = 0; mask < (1 << (n - 1)); ++mask) {
int cnt = __builtin_popcount(mask) + 1;
if (cnt < a || cnt > b) {
continue;
}
ll cur = 0;
ll sum = y[0];
for (int bit = 0; bit < n - 1; ++bit) {
if (mask & (1 << bit)) {
cur |= sum;
sum = y[bit + 1];
} else {
sum += y[bit + 1];
}
}
cur |= sum;
ans = min(ans, cur);
}
cout << ans;
} else {
for (int i = 1; i <= n; ++i) {
cin >> y[i];
pref[i] = pref[i - 1] + y[i];
}
for (int i = 1; i <= n; ++i) {
dp[i][1][pref[i]] = true;
}
for (int k = 2; k <= b; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = i - 1; j >= 1; --j) {
for (int x = 0; x < Y; ++x) {
if (dp[j][k - 1][x]) {
dp[i][k][x | (pref[i] - pref[j])] = true;
}
}
}
}
}
ll ans = inf;
for (int k = a; k <= b; ++k) {
for (int x = 0; x < Y; ++x) {
if (dp[n][k][x]) {
ans = min(ans, (ll)x);
}
}
}
cout << ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
30 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
4 ms |
324 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
4 ms |
212 KB |
Output is correct |
26 |
Correct |
28 ms |
316 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
5 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
27 ms |
212 KB |
Output is correct |
34 |
Correct |
30 ms |
324 KB |
Output is correct |
35 |
Correct |
2 ms |
212 KB |
Output is correct |
36 |
Correct |
30 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
30 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
232 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
320 KB |
Output is correct |
23 |
Correct |
4 ms |
320 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
4 ms |
212 KB |
Output is correct |
26 |
Correct |
31 ms |
212 KB |
Output is correct |
27 |
Correct |
6 ms |
724 KB |
Output is correct |
28 |
Correct |
5 ms |
724 KB |
Output is correct |
29 |
Correct |
5 ms |
724 KB |
Output is correct |
30 |
Correct |
22 ms |
1600 KB |
Output is correct |
31 |
Correct |
35 ms |
1920 KB |
Output is correct |
32 |
Correct |
34 ms |
1928 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
39 ms |
1988 KB |
Output is correct |
35 |
Correct |
29 ms |
1808 KB |
Output is correct |
36 |
Correct |
17 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
324 KB |
Output is correct |
13 |
Correct |
29 ms |
212 KB |
Output is correct |
14 |
Correct |
6 ms |
724 KB |
Output is correct |
15 |
Correct |
6 ms |
724 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
26 ms |
1492 KB |
Output is correct |
18 |
Correct |
35 ms |
1972 KB |
Output is correct |
19 |
Correct |
34 ms |
1920 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
33 ms |
2004 KB |
Output is correct |
22 |
Correct |
32 ms |
1748 KB |
Output is correct |
23 |
Correct |
21 ms |
1312 KB |
Output is correct |
24 |
Correct |
38 ms |
2040 KB |
Output is correct |
25 |
Correct |
32 ms |
1624 KB |
Output is correct |
26 |
Correct |
134 ms |
3588 KB |
Output is correct |
27 |
Correct |
360 ms |
7604 KB |
Output is correct |
28 |
Correct |
771 ms |
10356 KB |
Output is correct |
29 |
Correct |
761 ms |
10516 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
395 ms |
7508 KB |
Output is correct |
32 |
Correct |
562 ms |
9644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
320 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
3 ms |
212 KB |
Output is correct |
13 |
Correct |
30 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
4 ms |
320 KB |
Output is correct |
26 |
Correct |
27 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
4 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
27 ms |
328 KB |
Output is correct |
34 |
Correct |
30 ms |
212 KB |
Output is correct |
35 |
Correct |
2 ms |
212 KB |
Output is correct |
36 |
Correct |
32 ms |
212 KB |
Output is correct |
37 |
Correct |
7 ms |
724 KB |
Output is correct |
38 |
Correct |
4 ms |
724 KB |
Output is correct |
39 |
Correct |
5 ms |
724 KB |
Output is correct |
40 |
Correct |
24 ms |
1492 KB |
Output is correct |
41 |
Correct |
42 ms |
1944 KB |
Output is correct |
42 |
Correct |
36 ms |
1944 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
35 ms |
2032 KB |
Output is correct |
45 |
Correct |
30 ms |
1844 KB |
Output is correct |
46 |
Correct |
21 ms |
1316 KB |
Output is correct |
47 |
Correct |
38 ms |
1996 KB |
Output is correct |
48 |
Correct |
29 ms |
1604 KB |
Output is correct |
49 |
Correct |
103 ms |
3472 KB |
Output is correct |
50 |
Correct |
382 ms |
7376 KB |
Output is correct |
51 |
Correct |
720 ms |
10412 KB |
Output is correct |
52 |
Correct |
745 ms |
10520 KB |
Output is correct |
53 |
Correct |
1 ms |
724 KB |
Output is correct |
54 |
Correct |
361 ms |
7532 KB |
Output is correct |
55 |
Correct |
547 ms |
9672 KB |
Output is correct |
56 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
30 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
28 ms |
212 KB |
Output is correct |
21 |
Correct |
30 ms |
328 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
30 ms |
240 KB |
Output is correct |
24 |
Correct |
6 ms |
724 KB |
Output is correct |
25 |
Correct |
5 ms |
704 KB |
Output is correct |
26 |
Correct |
6 ms |
724 KB |
Output is correct |
27 |
Correct |
21 ms |
1532 KB |
Output is correct |
28 |
Correct |
35 ms |
1992 KB |
Output is correct |
29 |
Correct |
38 ms |
1992 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
35 ms |
1920 KB |
Output is correct |
32 |
Correct |
28 ms |
1740 KB |
Output is correct |
33 |
Correct |
18 ms |
1216 KB |
Output is correct |
34 |
Correct |
39 ms |
1996 KB |
Output is correct |
35 |
Correct |
31 ms |
1616 KB |
Output is correct |
36 |
Correct |
110 ms |
3472 KB |
Output is correct |
37 |
Correct |
375 ms |
7376 KB |
Output is correct |
38 |
Correct |
714 ms |
10312 KB |
Output is correct |
39 |
Correct |
749 ms |
10236 KB |
Output is correct |
40 |
Correct |
1 ms |
708 KB |
Output is correct |
41 |
Correct |
359 ms |
7504 KB |
Output is correct |
42 |
Correct |
597 ms |
9580 KB |
Output is correct |
43 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |