#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int maxn = 105;
long long A[2*maxn], inp[2*maxn];
int bs_A[2*maxn][65];
long long dp[maxn][8*maxn*maxn];
long long tmp[8*maxn*maxn];
int main(){
int m;
long long L;
cin >> m >> L;
for(int i = 0; i <= 2*m; i++)cin >> A[i];
if(L < 0){
L*=-1;
for(int i = 1; i <= m; i++)swap(A[i-m], A[i+m]);
}
for(int i = 0; i <= 2*m; i++){
if(i == m)continue;
for(int j = 0; j <= 60; j++){
if(A[i] == 0)break;
bs_A[i][j] = A[i]&1 ? 1 : 2;
A[i] = (A[i]-1)/2;
}
}
int sum = m*(m+1)*4;
memset(dp, -1, sizeof(dp));
dp[1][sum] = 0;
for(int b = 0; b <= 60; b++){
for(int i = 1; i <= m; i++){
for(int j = 0; j <= 2*sum; j++){
if(dp[i][j] == -1)continue;
for(int p_val = 0; p_val <= bs_A[m+i][b]; p_val++){
for(int n_val = 0; n_val <= bs_A[m-i][b]; n_val++){
int nw = j + (p_val - n_val)*i;
long long cost = p_val + n_val;
cost <<= b;
assert(0 <= nw && nw <= 2*sum);
dp[i+1][nw] = max(dp[i+1][nw], dp[i][j] + cost);
}
}
}
}
for(int j = 0; j <= 2*sum; j++)tmp[j] = -1;
for(int i = 0; i <= 2*sum; i++){
if(((i&1)^(sum&1)) != ((L>>b)&1))continue;
int ri = i - sum, pos;
if(ri < 0)pos = (ri-1)/2 + sum;
else pos = ri/2 + sum;
assert(pos >= 0 && pos <= 2*sum);
tmp[pos] = max(tmp[pos], dp[m+1][i]);
}
for(int i = 2; i <= m+1; i++){
for(int j = 0; j <= 2*sum; j++)dp[i][j] = -1;
}
for(int i = 0; i <= 2*sum; i++)dp[1][i] = tmp[i];
}
if(dp[1][sum] == -1)cout << "impossible";
else cout << dp[1][sum] + A[m];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
72796 KB |
Output is correct |
2 |
Correct |
28 ms |
72764 KB |
Output is correct |
3 |
Correct |
30 ms |
72784 KB |
Output is correct |
4 |
Correct |
29 ms |
72792 KB |
Output is correct |
5 |
Correct |
106 ms |
72948 KB |
Output is correct |
6 |
Correct |
111 ms |
73040 KB |
Output is correct |
7 |
Correct |
110 ms |
73040 KB |
Output is correct |
8 |
Incorrect |
106 ms |
73044 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
72796 KB |
Output is correct |
2 |
Correct |
28 ms |
72764 KB |
Output is correct |
3 |
Correct |
30 ms |
72784 KB |
Output is correct |
4 |
Correct |
29 ms |
72792 KB |
Output is correct |
5 |
Correct |
106 ms |
72948 KB |
Output is correct |
6 |
Correct |
111 ms |
73040 KB |
Output is correct |
7 |
Correct |
110 ms |
73040 KB |
Output is correct |
8 |
Incorrect |
106 ms |
73044 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
72796 KB |
Output is correct |
2 |
Correct |
51 ms |
72796 KB |
Output is correct |
3 |
Correct |
46 ms |
72868 KB |
Output is correct |
4 |
Correct |
51 ms |
72964 KB |
Output is correct |
5 |
Correct |
48 ms |
72796 KB |
Output is correct |
6 |
Correct |
45 ms |
72788 KB |
Output is correct |
7 |
Correct |
51 ms |
72856 KB |
Output is correct |
8 |
Correct |
50 ms |
72792 KB |
Output is correct |
9 |
Correct |
59 ms |
72784 KB |
Output is correct |
10 |
Correct |
50 ms |
72796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
72796 KB |
Output is correct |
2 |
Correct |
51 ms |
72796 KB |
Output is correct |
3 |
Correct |
46 ms |
72868 KB |
Output is correct |
4 |
Correct |
51 ms |
72964 KB |
Output is correct |
5 |
Correct |
48 ms |
72796 KB |
Output is correct |
6 |
Correct |
45 ms |
72788 KB |
Output is correct |
7 |
Correct |
51 ms |
72856 KB |
Output is correct |
8 |
Correct |
50 ms |
72792 KB |
Output is correct |
9 |
Correct |
59 ms |
72784 KB |
Output is correct |
10 |
Correct |
50 ms |
72796 KB |
Output is correct |
11 |
Correct |
31 ms |
72792 KB |
Output is correct |
12 |
Correct |
29 ms |
72828 KB |
Output is correct |
13 |
Correct |
28 ms |
72796 KB |
Output is correct |
14 |
Correct |
32 ms |
72784 KB |
Output is correct |
15 |
Correct |
51 ms |
72788 KB |
Output is correct |
16 |
Correct |
46 ms |
72792 KB |
Output is correct |
17 |
Correct |
48 ms |
73160 KB |
Output is correct |
18 |
Correct |
51 ms |
72788 KB |
Output is correct |
19 |
Correct |
52 ms |
72788 KB |
Output is correct |
20 |
Correct |
51 ms |
72984 KB |
Output is correct |
21 |
Correct |
60 ms |
73048 KB |
Output is correct |
22 |
Correct |
60 ms |
72796 KB |
Output is correct |
23 |
Correct |
51 ms |
72916 KB |
Output is correct |
24 |
Correct |
57 ms |
72796 KB |
Output is correct |
25 |
Correct |
50 ms |
72796 KB |
Output is correct |
26 |
Incorrect |
51 ms |
72788 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
72796 KB |
Output is correct |
2 |
Correct |
51 ms |
72796 KB |
Output is correct |
3 |
Correct |
46 ms |
72868 KB |
Output is correct |
4 |
Correct |
51 ms |
72964 KB |
Output is correct |
5 |
Correct |
48 ms |
72796 KB |
Output is correct |
6 |
Correct |
45 ms |
72788 KB |
Output is correct |
7 |
Correct |
51 ms |
72856 KB |
Output is correct |
8 |
Correct |
50 ms |
72792 KB |
Output is correct |
9 |
Correct |
59 ms |
72784 KB |
Output is correct |
10 |
Correct |
50 ms |
72796 KB |
Output is correct |
11 |
Correct |
34 ms |
72784 KB |
Output is correct |
12 |
Correct |
50 ms |
72796 KB |
Output is correct |
13 |
Correct |
56 ms |
72788 KB |
Output is correct |
14 |
Correct |
48 ms |
72796 KB |
Output is correct |
15 |
Correct |
48 ms |
72796 KB |
Output is correct |
16 |
Correct |
46 ms |
72796 KB |
Output is correct |
17 |
Correct |
46 ms |
72788 KB |
Output is correct |
18 |
Correct |
48 ms |
72796 KB |
Output is correct |
19 |
Correct |
49 ms |
72788 KB |
Output is correct |
20 |
Correct |
47 ms |
72796 KB |
Output is correct |
21 |
Correct |
109 ms |
73052 KB |
Output is correct |
22 |
Correct |
102 ms |
73044 KB |
Output is correct |
23 |
Correct |
110 ms |
73052 KB |
Output is correct |
24 |
Correct |
108 ms |
73104 KB |
Output is correct |
25 |
Correct |
112 ms |
73040 KB |
Output is correct |
26 |
Correct |
117 ms |
73040 KB |
Output is correct |
27 |
Correct |
114 ms |
73048 KB |
Output is correct |
28 |
Correct |
133 ms |
73292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
72796 KB |
Output is correct |
2 |
Correct |
28 ms |
72764 KB |
Output is correct |
3 |
Correct |
30 ms |
72784 KB |
Output is correct |
4 |
Correct |
29 ms |
72792 KB |
Output is correct |
5 |
Correct |
106 ms |
72948 KB |
Output is correct |
6 |
Correct |
111 ms |
73040 KB |
Output is correct |
7 |
Correct |
110 ms |
73040 KB |
Output is correct |
8 |
Incorrect |
106 ms |
73044 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
72796 KB |
Output is correct |
2 |
Correct |
51 ms |
72796 KB |
Output is correct |
3 |
Correct |
46 ms |
72868 KB |
Output is correct |
4 |
Correct |
51 ms |
72964 KB |
Output is correct |
5 |
Correct |
48 ms |
72796 KB |
Output is correct |
6 |
Correct |
45 ms |
72788 KB |
Output is correct |
7 |
Correct |
51 ms |
72856 KB |
Output is correct |
8 |
Correct |
50 ms |
72792 KB |
Output is correct |
9 |
Correct |
59 ms |
72784 KB |
Output is correct |
10 |
Correct |
50 ms |
72796 KB |
Output is correct |
11 |
Correct |
34 ms |
72784 KB |
Output is correct |
12 |
Correct |
50 ms |
72796 KB |
Output is correct |
13 |
Correct |
56 ms |
72788 KB |
Output is correct |
14 |
Correct |
48 ms |
72796 KB |
Output is correct |
15 |
Correct |
48 ms |
72796 KB |
Output is correct |
16 |
Correct |
46 ms |
72796 KB |
Output is correct |
17 |
Correct |
46 ms |
72788 KB |
Output is correct |
18 |
Correct |
48 ms |
72796 KB |
Output is correct |
19 |
Correct |
49 ms |
72788 KB |
Output is correct |
20 |
Correct |
47 ms |
72796 KB |
Output is correct |
21 |
Correct |
109 ms |
73052 KB |
Output is correct |
22 |
Correct |
102 ms |
73044 KB |
Output is correct |
23 |
Correct |
110 ms |
73052 KB |
Output is correct |
24 |
Correct |
108 ms |
73104 KB |
Output is correct |
25 |
Correct |
112 ms |
73040 KB |
Output is correct |
26 |
Correct |
117 ms |
73040 KB |
Output is correct |
27 |
Correct |
114 ms |
73048 KB |
Output is correct |
28 |
Correct |
133 ms |
73292 KB |
Output is correct |
29 |
Correct |
29 ms |
72796 KB |
Output is correct |
30 |
Correct |
53 ms |
72788 KB |
Output is correct |
31 |
Correct |
46 ms |
72796 KB |
Output is correct |
32 |
Correct |
51 ms |
72792 KB |
Output is correct |
33 |
Correct |
51 ms |
72796 KB |
Output is correct |
34 |
Correct |
52 ms |
72796 KB |
Output is correct |
35 |
Correct |
60 ms |
72788 KB |
Output is correct |
36 |
Correct |
49 ms |
72908 KB |
Output is correct |
37 |
Correct |
45 ms |
72988 KB |
Output is correct |
38 |
Correct |
47 ms |
72796 KB |
Output is correct |
39 |
Correct |
116 ms |
73080 KB |
Output is correct |
40 |
Correct |
105 ms |
73020 KB |
Output is correct |
41 |
Correct |
125 ms |
73044 KB |
Output is correct |
42 |
Correct |
108 ms |
73044 KB |
Output is correct |
43 |
Correct |
110 ms |
73052 KB |
Output is correct |
44 |
Correct |
115 ms |
73040 KB |
Output is correct |
45 |
Correct |
115 ms |
73040 KB |
Output is correct |
46 |
Correct |
110 ms |
73044 KB |
Output is correct |
47 |
Correct |
751 ms |
73456 KB |
Output is correct |
48 |
Correct |
740 ms |
73808 KB |
Output is correct |
49 |
Correct |
823 ms |
73552 KB |
Output is correct |
50 |
Correct |
784 ms |
73556 KB |
Output is correct |
51 |
Correct |
826 ms |
73564 KB |
Output is correct |
52 |
Correct |
810 ms |
73820 KB |
Output is correct |
53 |
Correct |
867 ms |
73816 KB |
Output is correct |
54 |
Correct |
809 ms |
73592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
72796 KB |
Output is correct |
2 |
Correct |
28 ms |
72764 KB |
Output is correct |
3 |
Correct |
30 ms |
72784 KB |
Output is correct |
4 |
Correct |
29 ms |
72792 KB |
Output is correct |
5 |
Correct |
106 ms |
72948 KB |
Output is correct |
6 |
Correct |
111 ms |
73040 KB |
Output is correct |
7 |
Correct |
110 ms |
73040 KB |
Output is correct |
8 |
Incorrect |
106 ms |
73044 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
72796 KB |
Output is correct |
2 |
Correct |
51 ms |
72796 KB |
Output is correct |
3 |
Correct |
46 ms |
72868 KB |
Output is correct |
4 |
Correct |
51 ms |
72964 KB |
Output is correct |
5 |
Correct |
48 ms |
72796 KB |
Output is correct |
6 |
Correct |
45 ms |
72788 KB |
Output is correct |
7 |
Correct |
51 ms |
72856 KB |
Output is correct |
8 |
Correct |
50 ms |
72792 KB |
Output is correct |
9 |
Correct |
59 ms |
72784 KB |
Output is correct |
10 |
Correct |
50 ms |
72796 KB |
Output is correct |
11 |
Correct |
34 ms |
72784 KB |
Output is correct |
12 |
Correct |
50 ms |
72796 KB |
Output is correct |
13 |
Correct |
56 ms |
72788 KB |
Output is correct |
14 |
Correct |
48 ms |
72796 KB |
Output is correct |
15 |
Correct |
48 ms |
72796 KB |
Output is correct |
16 |
Correct |
46 ms |
72796 KB |
Output is correct |
17 |
Correct |
46 ms |
72788 KB |
Output is correct |
18 |
Correct |
48 ms |
72796 KB |
Output is correct |
19 |
Correct |
49 ms |
72788 KB |
Output is correct |
20 |
Correct |
47 ms |
72796 KB |
Output is correct |
21 |
Correct |
109 ms |
73052 KB |
Output is correct |
22 |
Correct |
102 ms |
73044 KB |
Output is correct |
23 |
Correct |
110 ms |
73052 KB |
Output is correct |
24 |
Correct |
108 ms |
73104 KB |
Output is correct |
25 |
Correct |
112 ms |
73040 KB |
Output is correct |
26 |
Correct |
117 ms |
73040 KB |
Output is correct |
27 |
Correct |
114 ms |
73048 KB |
Output is correct |
28 |
Correct |
133 ms |
73292 KB |
Output is correct |
29 |
Correct |
29 ms |
72796 KB |
Output is correct |
30 |
Correct |
53 ms |
72788 KB |
Output is correct |
31 |
Correct |
46 ms |
72796 KB |
Output is correct |
32 |
Correct |
51 ms |
72792 KB |
Output is correct |
33 |
Correct |
51 ms |
72796 KB |
Output is correct |
34 |
Correct |
52 ms |
72796 KB |
Output is correct |
35 |
Correct |
60 ms |
72788 KB |
Output is correct |
36 |
Correct |
49 ms |
72908 KB |
Output is correct |
37 |
Correct |
45 ms |
72988 KB |
Output is correct |
38 |
Correct |
47 ms |
72796 KB |
Output is correct |
39 |
Correct |
116 ms |
73080 KB |
Output is correct |
40 |
Correct |
105 ms |
73020 KB |
Output is correct |
41 |
Correct |
125 ms |
73044 KB |
Output is correct |
42 |
Correct |
108 ms |
73044 KB |
Output is correct |
43 |
Correct |
110 ms |
73052 KB |
Output is correct |
44 |
Correct |
115 ms |
73040 KB |
Output is correct |
45 |
Correct |
115 ms |
73040 KB |
Output is correct |
46 |
Correct |
110 ms |
73044 KB |
Output is correct |
47 |
Correct |
751 ms |
73456 KB |
Output is correct |
48 |
Correct |
740 ms |
73808 KB |
Output is correct |
49 |
Correct |
823 ms |
73552 KB |
Output is correct |
50 |
Correct |
784 ms |
73556 KB |
Output is correct |
51 |
Correct |
826 ms |
73564 KB |
Output is correct |
52 |
Correct |
810 ms |
73820 KB |
Output is correct |
53 |
Correct |
867 ms |
73816 KB |
Output is correct |
54 |
Correct |
809 ms |
73592 KB |
Output is correct |
55 |
Correct |
33 ms |
72792 KB |
Output is correct |
56 |
Correct |
50 ms |
72796 KB |
Output is correct |
57 |
Correct |
85 ms |
72784 KB |
Output is correct |
58 |
Correct |
46 ms |
72788 KB |
Output is correct |
59 |
Correct |
45 ms |
72792 KB |
Output is correct |
60 |
Correct |
44 ms |
72852 KB |
Output is correct |
61 |
Correct |
47 ms |
72796 KB |
Output is correct |
62 |
Correct |
70 ms |
72784 KB |
Output is correct |
63 |
Correct |
78 ms |
72788 KB |
Output is correct |
64 |
Correct |
47 ms |
72988 KB |
Output is correct |
65 |
Correct |
116 ms |
72908 KB |
Output is correct |
66 |
Correct |
103 ms |
73040 KB |
Output is correct |
67 |
Correct |
115 ms |
73100 KB |
Output is correct |
68 |
Correct |
115 ms |
73096 KB |
Output is correct |
69 |
Correct |
119 ms |
73032 KB |
Output is correct |
70 |
Correct |
125 ms |
73000 KB |
Output is correct |
71 |
Correct |
124 ms |
72948 KB |
Output is correct |
72 |
Correct |
135 ms |
73092 KB |
Output is correct |
73 |
Correct |
780 ms |
73556 KB |
Output is correct |
74 |
Correct |
769 ms |
73440 KB |
Output is correct |
75 |
Correct |
874 ms |
73580 KB |
Output is correct |
76 |
Correct |
806 ms |
73552 KB |
Output is correct |
77 |
Correct |
919 ms |
73552 KB |
Output is correct |
78 |
Correct |
892 ms |
73524 KB |
Output is correct |
79 |
Correct |
913 ms |
73588 KB |
Output is correct |
80 |
Correct |
863 ms |
73588 KB |
Output is correct |
81 |
Runtime error |
2 ms |
348 KB |
Execution killed with signal 11 |
82 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
72796 KB |
Output is correct |
2 |
Correct |
28 ms |
72764 KB |
Output is correct |
3 |
Correct |
30 ms |
72784 KB |
Output is correct |
4 |
Correct |
29 ms |
72792 KB |
Output is correct |
5 |
Correct |
106 ms |
72948 KB |
Output is correct |
6 |
Correct |
111 ms |
73040 KB |
Output is correct |
7 |
Correct |
110 ms |
73040 KB |
Output is correct |
8 |
Incorrect |
106 ms |
73044 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |