/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int BITS = 60;
const ll INF = LLONG_MAX / 2;
int M;
ll L;
int* A[BITS];
int S;
ll* maxTake[BITS];
ll* maxTakeBit;
void init () {
for (int bit = 0; bit < BITS; bit++) {
A[bit] = new int[M * 2 + 1] + M;
maxTake[bit] = new ll[S * 2 + 1] + S;
fill(A[bit] - M, A[bit] + M + 1, 0);
fill(maxTake[bit] - S, maxTake[bit] + S + 1, -INF);
}
maxTakeBit = new ll[S * 2 + 1] + S;
}
void solveBit (int bit) {
fill(maxTakeBit - S, maxTakeBit + S + 1, -INF);
maxTakeBit[0] = 0;
for (int l = -M; l <= M; l++) {
if (l < 0) {
for (int i = 1; i <= A[bit][l]; i++) {
for (int s = -S - l; s <= +S; s++) {
if (maxTakeBit[s] != -INF) {
maxTakeBit[s + l] = max(maxTakeBit[s + l], maxTakeBit[s] + 1);
}
}
}
} else {
for (int i = 1; i <= A[bit][l]; i++) {
for (int s = +S - l; s >= -S; s--) {
if (maxTakeBit[s] != -INF) {
maxTakeBit[s + l] = max(maxTakeBit[s + l], maxTakeBit[s] + 1);
}
}
}
}
}
}
void update (ll &x, const ll &y) {
if (y > x) {
x = y;
}
}
mt19937 rnd(0);
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> M >> L;
S = M * (M + 1);
init();
for (int l = -M; l <= +M; l++) {
ll cnt; cin >> cnt;
int bit = 0;
while (((ll) 1 << bit) <= cnt) {
cnt -= ((ll) 1 << bit);
A[bit][l]++;
bit++;
}
for (int bit = 0; bit < BITS; bit++) {
if ((cnt >> bit) & 1) {
A[bit][l]++;
}
}
}
solveBit(0);
for (int here = -S; here <= +S; here++) {
int sum = here - (L & 1);
if (sum % 2 == 0) {
update(maxTake[0][sum / 2], maxTakeBit[here]);
}
}
for (int bit = 1; bit < BITS; bit++) {
solveBit(bit);
for (int carry = -S; carry <= +S; carry++) {
if (maxTake[bit - 1][carry] != -INF) {
for (int here = -S; here <= +S; here++) {
int sum = carry + here - ((L >> bit) & 1);
if (maxTakeBit[here] != -INF && sum % 2 == 0) {
update(maxTake[bit][sum / 2], maxTake[bit - 1][carry] + maxTakeBit[here] * ((ll) 1 << bit));
}
}
}
}
}
ll answer = maxTake[BITS - 1][0];
if (answer != -INF) {
cout << answer << "\n";
} else {
cout << "impossible\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
79 ms |
2772 KB |
Output is correct |
6 |
Correct |
81 ms |
2776 KB |
Output is correct |
7 |
Correct |
46 ms |
2772 KB |
Output is correct |
8 |
Incorrect |
83 ms |
2772 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
79 ms |
2772 KB |
Output is correct |
6 |
Correct |
81 ms |
2776 KB |
Output is correct |
7 |
Correct |
46 ms |
2772 KB |
Output is correct |
8 |
Incorrect |
83 ms |
2772 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
20 ms |
1108 KB |
Output is correct |
3 |
Correct |
8 ms |
1108 KB |
Output is correct |
4 |
Correct |
19 ms |
1232 KB |
Output is correct |
5 |
Correct |
25 ms |
1108 KB |
Output is correct |
6 |
Correct |
6 ms |
1224 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
15 ms |
1232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
20 ms |
1108 KB |
Output is correct |
3 |
Correct |
8 ms |
1108 KB |
Output is correct |
4 |
Correct |
19 ms |
1232 KB |
Output is correct |
5 |
Correct |
25 ms |
1108 KB |
Output is correct |
6 |
Correct |
6 ms |
1224 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
15 ms |
1232 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
228 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
20 ms |
1228 KB |
Output is correct |
16 |
Correct |
8 ms |
1224 KB |
Output is correct |
17 |
Correct |
20 ms |
1232 KB |
Output is correct |
18 |
Correct |
25 ms |
1224 KB |
Output is correct |
19 |
Correct |
6 ms |
1108 KB |
Output is correct |
20 |
Correct |
5 ms |
1228 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1108 KB |
Output is correct |
23 |
Correct |
12 ms |
1232 KB |
Output is correct |
24 |
Correct |
74 ms |
1212 KB |
Output is correct |
25 |
Correct |
15 ms |
1228 KB |
Output is correct |
26 |
Incorrect |
52 ms |
1108 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
20 ms |
1108 KB |
Output is correct |
3 |
Correct |
8 ms |
1108 KB |
Output is correct |
4 |
Correct |
19 ms |
1232 KB |
Output is correct |
5 |
Correct |
25 ms |
1108 KB |
Output is correct |
6 |
Correct |
6 ms |
1224 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
15 ms |
1232 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
24 ms |
1108 KB |
Output is correct |
13 |
Correct |
13 ms |
1240 KB |
Output is correct |
14 |
Correct |
19 ms |
1108 KB |
Output is correct |
15 |
Correct |
29 ms |
1108 KB |
Output is correct |
16 |
Correct |
6 ms |
1108 KB |
Output is correct |
17 |
Correct |
7 ms |
1108 KB |
Output is correct |
18 |
Correct |
4 ms |
1108 KB |
Output is correct |
19 |
Correct |
4 ms |
1108 KB |
Output is correct |
20 |
Correct |
11 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
2772 KB |
Output is correct |
22 |
Correct |
4 ms |
2772 KB |
Output is correct |
23 |
Correct |
118 ms |
2772 KB |
Output is correct |
24 |
Correct |
118 ms |
2772 KB |
Output is correct |
25 |
Correct |
168 ms |
2892 KB |
Output is correct |
26 |
Correct |
194 ms |
2772 KB |
Output is correct |
27 |
Correct |
132 ms |
2772 KB |
Output is correct |
28 |
Correct |
111 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
79 ms |
2772 KB |
Output is correct |
6 |
Correct |
81 ms |
2776 KB |
Output is correct |
7 |
Correct |
46 ms |
2772 KB |
Output is correct |
8 |
Incorrect |
83 ms |
2772 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
20 ms |
1108 KB |
Output is correct |
3 |
Correct |
8 ms |
1108 KB |
Output is correct |
4 |
Correct |
19 ms |
1232 KB |
Output is correct |
5 |
Correct |
25 ms |
1108 KB |
Output is correct |
6 |
Correct |
6 ms |
1224 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
15 ms |
1232 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
24 ms |
1108 KB |
Output is correct |
13 |
Correct |
13 ms |
1240 KB |
Output is correct |
14 |
Correct |
19 ms |
1108 KB |
Output is correct |
15 |
Correct |
29 ms |
1108 KB |
Output is correct |
16 |
Correct |
6 ms |
1108 KB |
Output is correct |
17 |
Correct |
7 ms |
1108 KB |
Output is correct |
18 |
Correct |
4 ms |
1108 KB |
Output is correct |
19 |
Correct |
4 ms |
1108 KB |
Output is correct |
20 |
Correct |
11 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
2772 KB |
Output is correct |
22 |
Correct |
4 ms |
2772 KB |
Output is correct |
23 |
Correct |
118 ms |
2772 KB |
Output is correct |
24 |
Correct |
118 ms |
2772 KB |
Output is correct |
25 |
Correct |
168 ms |
2892 KB |
Output is correct |
26 |
Correct |
194 ms |
2772 KB |
Output is correct |
27 |
Correct |
132 ms |
2772 KB |
Output is correct |
28 |
Correct |
111 ms |
2812 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
21 ms |
1108 KB |
Output is correct |
31 |
Correct |
9 ms |
1224 KB |
Output is correct |
32 |
Correct |
20 ms |
1224 KB |
Output is correct |
33 |
Correct |
23 ms |
1108 KB |
Output is correct |
34 |
Correct |
8 ms |
1228 KB |
Output is correct |
35 |
Correct |
6 ms |
1236 KB |
Output is correct |
36 |
Correct |
5 ms |
1232 KB |
Output is correct |
37 |
Correct |
4 ms |
1108 KB |
Output is correct |
38 |
Correct |
13 ms |
1228 KB |
Output is correct |
39 |
Correct |
3 ms |
2756 KB |
Output is correct |
40 |
Correct |
4 ms |
2772 KB |
Output is correct |
41 |
Correct |
122 ms |
2772 KB |
Output is correct |
42 |
Correct |
89 ms |
2772 KB |
Output is correct |
43 |
Correct |
144 ms |
2772 KB |
Output is correct |
44 |
Correct |
178 ms |
2772 KB |
Output is correct |
45 |
Correct |
118 ms |
2772 KB |
Output is correct |
46 |
Correct |
105 ms |
2764 KB |
Output is correct |
47 |
Correct |
13 ms |
10160 KB |
Output is correct |
48 |
Correct |
16 ms |
10068 KB |
Output is correct |
49 |
Correct |
1918 ms |
10148 KB |
Output is correct |
50 |
Correct |
880 ms |
10160 KB |
Output is correct |
51 |
Correct |
2401 ms |
10136 KB |
Output is correct |
52 |
Correct |
2261 ms |
10144 KB |
Output is correct |
53 |
Correct |
2081 ms |
10148 KB |
Output is correct |
54 |
Correct |
1224 ms |
10148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
79 ms |
2772 KB |
Output is correct |
6 |
Correct |
81 ms |
2776 KB |
Output is correct |
7 |
Correct |
46 ms |
2772 KB |
Output is correct |
8 |
Incorrect |
83 ms |
2772 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
20 ms |
1108 KB |
Output is correct |
3 |
Correct |
8 ms |
1108 KB |
Output is correct |
4 |
Correct |
19 ms |
1232 KB |
Output is correct |
5 |
Correct |
25 ms |
1108 KB |
Output is correct |
6 |
Correct |
6 ms |
1224 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
15 ms |
1232 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
24 ms |
1108 KB |
Output is correct |
13 |
Correct |
13 ms |
1240 KB |
Output is correct |
14 |
Correct |
19 ms |
1108 KB |
Output is correct |
15 |
Correct |
29 ms |
1108 KB |
Output is correct |
16 |
Correct |
6 ms |
1108 KB |
Output is correct |
17 |
Correct |
7 ms |
1108 KB |
Output is correct |
18 |
Correct |
4 ms |
1108 KB |
Output is correct |
19 |
Correct |
4 ms |
1108 KB |
Output is correct |
20 |
Correct |
11 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
2772 KB |
Output is correct |
22 |
Correct |
4 ms |
2772 KB |
Output is correct |
23 |
Correct |
118 ms |
2772 KB |
Output is correct |
24 |
Correct |
118 ms |
2772 KB |
Output is correct |
25 |
Correct |
168 ms |
2892 KB |
Output is correct |
26 |
Correct |
194 ms |
2772 KB |
Output is correct |
27 |
Correct |
132 ms |
2772 KB |
Output is correct |
28 |
Correct |
111 ms |
2812 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
21 ms |
1108 KB |
Output is correct |
31 |
Correct |
9 ms |
1224 KB |
Output is correct |
32 |
Correct |
20 ms |
1224 KB |
Output is correct |
33 |
Correct |
23 ms |
1108 KB |
Output is correct |
34 |
Correct |
8 ms |
1228 KB |
Output is correct |
35 |
Correct |
6 ms |
1236 KB |
Output is correct |
36 |
Correct |
5 ms |
1232 KB |
Output is correct |
37 |
Correct |
4 ms |
1108 KB |
Output is correct |
38 |
Correct |
13 ms |
1228 KB |
Output is correct |
39 |
Correct |
3 ms |
2756 KB |
Output is correct |
40 |
Correct |
4 ms |
2772 KB |
Output is correct |
41 |
Correct |
122 ms |
2772 KB |
Output is correct |
42 |
Correct |
89 ms |
2772 KB |
Output is correct |
43 |
Correct |
144 ms |
2772 KB |
Output is correct |
44 |
Correct |
178 ms |
2772 KB |
Output is correct |
45 |
Correct |
118 ms |
2772 KB |
Output is correct |
46 |
Correct |
105 ms |
2764 KB |
Output is correct |
47 |
Correct |
13 ms |
10160 KB |
Output is correct |
48 |
Correct |
16 ms |
10068 KB |
Output is correct |
49 |
Correct |
1918 ms |
10148 KB |
Output is correct |
50 |
Correct |
880 ms |
10160 KB |
Output is correct |
51 |
Correct |
2401 ms |
10136 KB |
Output is correct |
52 |
Correct |
2261 ms |
10144 KB |
Output is correct |
53 |
Correct |
2081 ms |
10148 KB |
Output is correct |
54 |
Correct |
1224 ms |
10148 KB |
Output is correct |
55 |
Correct |
0 ms |
340 KB |
Output is correct |
56 |
Correct |
23 ms |
1108 KB |
Output is correct |
57 |
Correct |
8 ms |
1116 KB |
Output is correct |
58 |
Correct |
19 ms |
1228 KB |
Output is correct |
59 |
Correct |
23 ms |
1228 KB |
Output is correct |
60 |
Correct |
7 ms |
1236 KB |
Output is correct |
61 |
Correct |
6 ms |
1108 KB |
Output is correct |
62 |
Correct |
4 ms |
1108 KB |
Output is correct |
63 |
Correct |
4 ms |
1108 KB |
Output is correct |
64 |
Correct |
11 ms |
1108 KB |
Output is correct |
65 |
Correct |
2 ms |
2772 KB |
Output is correct |
66 |
Correct |
3 ms |
2772 KB |
Output is correct |
67 |
Correct |
119 ms |
2772 KB |
Output is correct |
68 |
Correct |
93 ms |
2772 KB |
Output is correct |
69 |
Correct |
143 ms |
2772 KB |
Output is correct |
70 |
Correct |
178 ms |
2772 KB |
Output is correct |
71 |
Correct |
167 ms |
2772 KB |
Output is correct |
72 |
Correct |
104 ms |
2772 KB |
Output is correct |
73 |
Correct |
12 ms |
10068 KB |
Output is correct |
74 |
Correct |
17 ms |
10172 KB |
Output is correct |
75 |
Correct |
1825 ms |
10196 KB |
Output is correct |
76 |
Correct |
852 ms |
10144 KB |
Output is correct |
77 |
Correct |
2287 ms |
10164 KB |
Output is correct |
78 |
Correct |
2126 ms |
10152 KB |
Output is correct |
79 |
Correct |
2012 ms |
10140 KB |
Output is correct |
80 |
Correct |
1202 ms |
10140 KB |
Output is correct |
81 |
Execution timed out |
5044 ms |
86656 KB |
Time limit exceeded |
82 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
79 ms |
2772 KB |
Output is correct |
6 |
Correct |
81 ms |
2776 KB |
Output is correct |
7 |
Correct |
46 ms |
2772 KB |
Output is correct |
8 |
Incorrect |
83 ms |
2772 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |