#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXN = 2005;
const int MAXB = 45;
int N, A, B;
lint Y[MAXN];
bitset<MAXN> dp[2005]; // dp[pos][groups]
bool Calc(lint mask) {
for (int i = A; i <= B; i++) {
dp[N][i] = 1;
}
for (int pos = N - 1; pos >= 0; pos--) {
dp[pos] = 0;
lint sum = 0;
for (int nxt = pos; nxt < N; nxt++) {
sum += Y[nxt];
if ((sum | mask) == mask) {
dp[pos] |= dp[nxt + 1] >> 1;
}
}
}
return dp[0][0];
}
lint Solve() {
lint mask = (1ll << MAXB) - 1;
for (lint j = MAXB - 1; j >= 0; j--) {
if (Calc(mask - (1ll << j))) { // check if there is a grouping with cost as a subset of mask
mask -= 1ll << j;
}
}
return mask;
}
void Read() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N >> A >> B;
for (int i = 0; i < N; i++) {
cin >> Y[i];
}
}
int main() {
Read();
cout << Solve() << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
384 KB |
Output is correct |
29 |
Correct |
7 ms |
384 KB |
Output is correct |
30 |
Correct |
7 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
384 KB |
Output is correct |
32 |
Correct |
8 ms |
384 KB |
Output is correct |
33 |
Correct |
9 ms |
384 KB |
Output is correct |
34 |
Correct |
9 ms |
384 KB |
Output is correct |
35 |
Correct |
8 ms |
384 KB |
Output is correct |
36 |
Correct |
8 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
288 KB |
Output is correct |
16 |
Correct |
7 ms |
384 KB |
Output is correct |
17 |
Correct |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
384 KB |
Output is correct |
19 |
Correct |
9 ms |
384 KB |
Output is correct |
20 |
Correct |
9 ms |
384 KB |
Output is correct |
21 |
Correct |
8 ms |
384 KB |
Output is correct |
22 |
Correct |
8 ms |
384 KB |
Output is correct |
23 |
Correct |
9 ms |
384 KB |
Output is correct |
24 |
Correct |
8 ms |
384 KB |
Output is correct |
25 |
Correct |
11 ms |
384 KB |
Output is correct |
26 |
Correct |
14 ms |
384 KB |
Output is correct |
27 |
Correct |
17 ms |
512 KB |
Output is correct |
28 |
Correct |
20 ms |
384 KB |
Output is correct |
29 |
Correct |
19 ms |
384 KB |
Output is correct |
30 |
Correct |
20 ms |
384 KB |
Output is correct |
31 |
Correct |
19 ms |
384 KB |
Output is correct |
32 |
Correct |
20 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
6 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
384 KB |
Output is correct |
38 |
Correct |
6 ms |
384 KB |
Output is correct |
39 |
Correct |
7 ms |
384 KB |
Output is correct |
40 |
Correct |
7 ms |
384 KB |
Output is correct |
41 |
Correct |
9 ms |
384 KB |
Output is correct |
42 |
Correct |
9 ms |
384 KB |
Output is correct |
43 |
Correct |
9 ms |
384 KB |
Output is correct |
44 |
Correct |
8 ms |
512 KB |
Output is correct |
45 |
Correct |
8 ms |
384 KB |
Output is correct |
46 |
Correct |
9 ms |
384 KB |
Output is correct |
47 |
Correct |
9 ms |
384 KB |
Output is correct |
48 |
Correct |
10 ms |
384 KB |
Output is correct |
49 |
Correct |
14 ms |
384 KB |
Output is correct |
50 |
Correct |
17 ms |
384 KB |
Output is correct |
51 |
Correct |
18 ms |
384 KB |
Output is correct |
52 |
Correct |
20 ms |
384 KB |
Output is correct |
53 |
Correct |
21 ms |
384 KB |
Output is correct |
54 |
Correct |
19 ms |
384 KB |
Output is correct |
55 |
Correct |
19 ms |
384 KB |
Output is correct |
56 |
Correct |
7 ms |
384 KB |
Output is correct |
57 |
Correct |
8 ms |
384 KB |
Output is correct |
58 |
Correct |
9 ms |
384 KB |
Output is correct |
59 |
Correct |
10 ms |
384 KB |
Output is correct |
60 |
Correct |
9 ms |
384 KB |
Output is correct |
61 |
Correct |
12 ms |
384 KB |
Output is correct |
62 |
Correct |
13 ms |
384 KB |
Output is correct |
63 |
Correct |
11 ms |
384 KB |
Output is correct |
64 |
Correct |
18 ms |
384 KB |
Output is correct |
65 |
Correct |
6 ms |
384 KB |
Output is correct |
66 |
Correct |
7 ms |
384 KB |
Output is correct |
67 |
Correct |
8 ms |
384 KB |
Output is correct |
68 |
Correct |
9 ms |
384 KB |
Output is correct |
69 |
Correct |
10 ms |
384 KB |
Output is correct |
70 |
Correct |
10 ms |
384 KB |
Output is correct |
71 |
Correct |
10 ms |
384 KB |
Output is correct |
72 |
Correct |
11 ms |
384 KB |
Output is correct |
73 |
Correct |
10 ms |
384 KB |
Output is correct |
74 |
Correct |
11 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
7 ms |
384 KB |
Output is correct |
27 |
Correct |
7 ms |
384 KB |
Output is correct |
28 |
Correct |
8 ms |
384 KB |
Output is correct |
29 |
Correct |
8 ms |
384 KB |
Output is correct |
30 |
Correct |
8 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
384 KB |
Output is correct |
32 |
Correct |
9 ms |
384 KB |
Output is correct |
33 |
Correct |
10 ms |
384 KB |
Output is correct |
34 |
Correct |
8 ms |
384 KB |
Output is correct |
35 |
Correct |
11 ms |
384 KB |
Output is correct |
36 |
Correct |
14 ms |
384 KB |
Output is correct |
37 |
Correct |
17 ms |
384 KB |
Output is correct |
38 |
Correct |
19 ms |
384 KB |
Output is correct |
39 |
Correct |
19 ms |
384 KB |
Output is correct |
40 |
Correct |
19 ms |
384 KB |
Output is correct |
41 |
Correct |
18 ms |
384 KB |
Output is correct |
42 |
Correct |
20 ms |
384 KB |
Output is correct |
43 |
Correct |
6 ms |
384 KB |
Output is correct |
44 |
Correct |
8 ms |
384 KB |
Output is correct |
45 |
Correct |
9 ms |
384 KB |
Output is correct |
46 |
Correct |
9 ms |
384 KB |
Output is correct |
47 |
Correct |
9 ms |
384 KB |
Output is correct |
48 |
Correct |
11 ms |
384 KB |
Output is correct |
49 |
Correct |
11 ms |
384 KB |
Output is correct |
50 |
Correct |
11 ms |
384 KB |
Output is correct |
51 |
Correct |
10 ms |
384 KB |
Output is correct |
52 |
Correct |
123 ms |
512 KB |
Output is correct |
53 |
Correct |
199 ms |
632 KB |
Output is correct |
54 |
Correct |
345 ms |
764 KB |
Output is correct |
55 |
Correct |
324 ms |
632 KB |
Output is correct |
56 |
Execution timed out |
1084 ms |
1016 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |