#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
const int N = 2e2 + 5;
long long dp [N][N][N][2];
int pos [N];
int lim [N];
/*
* DP[N][N][N][2]
* Minimum time possible for being at pos [i, j] - 0 / 1, with x elements so far
*/
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n, tamanho;
cin >> n >> tamanho;
n += 2;
pos[0] = 0;
lim[0] = 1e9;
pos[n - 1] = 0;
lim[n - 1] = 1e9;
for (int i = 1; i < n - 1; i++) cin >> pos[i];
for (int i = 1; i < n - 1; i++) cin >> lim[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int x = 0; x < N; x++) {
dp[i][j][x][0] = dp[i][j][x][1] = 1e16;
}
}
}
dp[0][n - 1][0][0] = dp[0][n - 1][0][1] = 0;
for (int L = 0; L < n; L++) {
for (int R = n - 1; R >= 0; R--) {
for (int Q = 0; Q <= n; Q++) {
if (L + 1 < n && L + 1 < R) {
// ESQ -> ESQ
long long tempo = dp[L][R][Q][0] + pos[L + 1] - pos[L];
assert(tempo >= 0);
int QTS = Q + (tempo <= lim[L + 1]);
dp[L + 1][R][QTS][0] = min (dp[L + 1][R][QTS][0], tempo);
// DIR -> ESQ
tempo = dp[L][R][Q][1] + tamanho - pos[R] + pos[L + 1];
assert(tempo >= 0);
QTS = Q + (tempo <= lim[L + 1]);
dp[L + 1][R][QTS][0] = min (dp[L + 1][R][QTS][0], tempo);
}
if (R - 1 >= 0 && R - 1 > L) {
// DIR -> DIR
long long tempo = dp[L][R][Q][1] + abs (pos[R] - pos[R - 1]);
assert(tempo >= 0);
int QTS = Q + (tempo <= lim[R - 1]);
dp[L][R - 1][QTS][1] = min (dp[L][R - 1][QTS][1], tempo);
// ESQ -> DIR
tempo = dp[L][R][Q][0] + pos[L] + tamanho - pos[R - 1];
assert(tempo >= 0);
QTS = Q + (tempo <= lim[R - 1]);
dp[L][R - 1][QTS][1] = min (dp[L][R - 1][QTS][1], tempo);
}
}
}
}
int mx = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int x = 0; x < N; x++) {
if (dp[i][j][x][0] < 1e15 || dp[i][j][x][1] < 1e15) {
// cout << i << ' ' << j << ' ' <<' ' << x << ' ' << dp[i][j][x][1] << '\n';
mx = max (mx, x);
}
}
}
}
cout << mx << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
135160 KB |
Output is correct |
2 |
Correct |
76 ms |
135164 KB |
Output is correct |
3 |
Correct |
76 ms |
135288 KB |
Output is correct |
4 |
Correct |
79 ms |
135164 KB |
Output is correct |
5 |
Correct |
77 ms |
135160 KB |
Output is correct |
6 |
Correct |
77 ms |
135160 KB |
Output is correct |
7 |
Correct |
78 ms |
135256 KB |
Output is correct |
8 |
Correct |
80 ms |
135288 KB |
Output is correct |
9 |
Correct |
77 ms |
135160 KB |
Output is correct |
10 |
Correct |
78 ms |
135288 KB |
Output is correct |
11 |
Correct |
95 ms |
135232 KB |
Output is correct |
12 |
Correct |
78 ms |
135160 KB |
Output is correct |
13 |
Correct |
76 ms |
135288 KB |
Output is correct |
14 |
Correct |
75 ms |
135160 KB |
Output is correct |
15 |
Correct |
77 ms |
135160 KB |
Output is correct |
16 |
Correct |
81 ms |
135160 KB |
Output is correct |
17 |
Correct |
78 ms |
135160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
135160 KB |
Output is correct |
2 |
Correct |
76 ms |
135164 KB |
Output is correct |
3 |
Correct |
76 ms |
135288 KB |
Output is correct |
4 |
Correct |
79 ms |
135164 KB |
Output is correct |
5 |
Correct |
77 ms |
135160 KB |
Output is correct |
6 |
Correct |
77 ms |
135160 KB |
Output is correct |
7 |
Correct |
78 ms |
135256 KB |
Output is correct |
8 |
Correct |
80 ms |
135288 KB |
Output is correct |
9 |
Correct |
77 ms |
135160 KB |
Output is correct |
10 |
Correct |
78 ms |
135288 KB |
Output is correct |
11 |
Correct |
95 ms |
135232 KB |
Output is correct |
12 |
Correct |
78 ms |
135160 KB |
Output is correct |
13 |
Correct |
76 ms |
135288 KB |
Output is correct |
14 |
Correct |
75 ms |
135160 KB |
Output is correct |
15 |
Correct |
77 ms |
135160 KB |
Output is correct |
16 |
Correct |
81 ms |
135160 KB |
Output is correct |
17 |
Correct |
78 ms |
135160 KB |
Output is correct |
18 |
Correct |
89 ms |
135160 KB |
Output is correct |
19 |
Correct |
76 ms |
135160 KB |
Output is correct |
20 |
Correct |
83 ms |
135288 KB |
Output is correct |
21 |
Correct |
75 ms |
135148 KB |
Output is correct |
22 |
Correct |
76 ms |
135160 KB |
Output is correct |
23 |
Correct |
79 ms |
135160 KB |
Output is correct |
24 |
Correct |
78 ms |
135288 KB |
Output is correct |
25 |
Correct |
76 ms |
135164 KB |
Output is correct |
26 |
Correct |
77 ms |
135136 KB |
Output is correct |
27 |
Correct |
76 ms |
135160 KB |
Output is correct |
28 |
Correct |
80 ms |
135416 KB |
Output is correct |
29 |
Correct |
78 ms |
135208 KB |
Output is correct |
30 |
Correct |
87 ms |
135288 KB |
Output is correct |
31 |
Correct |
77 ms |
135288 KB |
Output is correct |
32 |
Correct |
76 ms |
135288 KB |
Output is correct |
33 |
Correct |
76 ms |
135416 KB |
Output is correct |
34 |
Correct |
79 ms |
135160 KB |
Output is correct |
35 |
Correct |
78 ms |
135160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
135160 KB |
Output is correct |
2 |
Correct |
76 ms |
135164 KB |
Output is correct |
3 |
Correct |
76 ms |
135288 KB |
Output is correct |
4 |
Correct |
79 ms |
135164 KB |
Output is correct |
5 |
Correct |
77 ms |
135160 KB |
Output is correct |
6 |
Correct |
77 ms |
135160 KB |
Output is correct |
7 |
Correct |
78 ms |
135256 KB |
Output is correct |
8 |
Correct |
80 ms |
135288 KB |
Output is correct |
9 |
Correct |
77 ms |
135160 KB |
Output is correct |
10 |
Correct |
78 ms |
135288 KB |
Output is correct |
11 |
Correct |
95 ms |
135232 KB |
Output is correct |
12 |
Correct |
78 ms |
135160 KB |
Output is correct |
13 |
Correct |
76 ms |
135288 KB |
Output is correct |
14 |
Correct |
75 ms |
135160 KB |
Output is correct |
15 |
Correct |
77 ms |
135160 KB |
Output is correct |
16 |
Correct |
81 ms |
135160 KB |
Output is correct |
17 |
Correct |
78 ms |
135160 KB |
Output is correct |
18 |
Correct |
182 ms |
135292 KB |
Output is correct |
19 |
Correct |
126 ms |
135288 KB |
Output is correct |
20 |
Correct |
95 ms |
135160 KB |
Output is correct |
21 |
Correct |
125 ms |
135288 KB |
Output is correct |
22 |
Correct |
149 ms |
135160 KB |
Output is correct |
23 |
Correct |
95 ms |
135288 KB |
Output is correct |
24 |
Correct |
88 ms |
135288 KB |
Output is correct |
25 |
Correct |
93 ms |
135288 KB |
Output is correct |
26 |
Correct |
81 ms |
135160 KB |
Output is correct |
27 |
Correct |
95 ms |
135160 KB |
Output is correct |
28 |
Correct |
84 ms |
135160 KB |
Output is correct |
29 |
Correct |
93 ms |
135160 KB |
Output is correct |
30 |
Correct |
88 ms |
135416 KB |
Output is correct |
31 |
Correct |
93 ms |
135160 KB |
Output is correct |
32 |
Correct |
83 ms |
135160 KB |
Output is correct |
33 |
Correct |
91 ms |
135160 KB |
Output is correct |
34 |
Correct |
80 ms |
135160 KB |
Output is correct |
35 |
Correct |
93 ms |
135160 KB |
Output is correct |
36 |
Correct |
83 ms |
135288 KB |
Output is correct |
37 |
Correct |
100 ms |
135292 KB |
Output is correct |
38 |
Correct |
83 ms |
135160 KB |
Output is correct |
39 |
Correct |
102 ms |
135288 KB |
Output is correct |
40 |
Correct |
85 ms |
135160 KB |
Output is correct |
41 |
Correct |
228 ms |
135208 KB |
Output is correct |
42 |
Correct |
157 ms |
135160 KB |
Output is correct |
43 |
Correct |
222 ms |
135288 KB |
Output is correct |
44 |
Correct |
155 ms |
135288 KB |
Output is correct |
45 |
Correct |
222 ms |
135160 KB |
Output is correct |
46 |
Correct |
160 ms |
135160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
135160 KB |
Output is correct |
2 |
Correct |
76 ms |
135164 KB |
Output is correct |
3 |
Correct |
76 ms |
135288 KB |
Output is correct |
4 |
Correct |
79 ms |
135164 KB |
Output is correct |
5 |
Correct |
77 ms |
135160 KB |
Output is correct |
6 |
Correct |
77 ms |
135160 KB |
Output is correct |
7 |
Correct |
78 ms |
135256 KB |
Output is correct |
8 |
Correct |
80 ms |
135288 KB |
Output is correct |
9 |
Correct |
77 ms |
135160 KB |
Output is correct |
10 |
Correct |
78 ms |
135288 KB |
Output is correct |
11 |
Correct |
95 ms |
135232 KB |
Output is correct |
12 |
Correct |
78 ms |
135160 KB |
Output is correct |
13 |
Correct |
76 ms |
135288 KB |
Output is correct |
14 |
Correct |
75 ms |
135160 KB |
Output is correct |
15 |
Correct |
77 ms |
135160 KB |
Output is correct |
16 |
Correct |
81 ms |
135160 KB |
Output is correct |
17 |
Correct |
78 ms |
135160 KB |
Output is correct |
18 |
Correct |
89 ms |
135160 KB |
Output is correct |
19 |
Correct |
76 ms |
135160 KB |
Output is correct |
20 |
Correct |
83 ms |
135288 KB |
Output is correct |
21 |
Correct |
75 ms |
135148 KB |
Output is correct |
22 |
Correct |
76 ms |
135160 KB |
Output is correct |
23 |
Correct |
79 ms |
135160 KB |
Output is correct |
24 |
Correct |
78 ms |
135288 KB |
Output is correct |
25 |
Correct |
76 ms |
135164 KB |
Output is correct |
26 |
Correct |
77 ms |
135136 KB |
Output is correct |
27 |
Correct |
76 ms |
135160 KB |
Output is correct |
28 |
Correct |
80 ms |
135416 KB |
Output is correct |
29 |
Correct |
78 ms |
135208 KB |
Output is correct |
30 |
Correct |
87 ms |
135288 KB |
Output is correct |
31 |
Correct |
77 ms |
135288 KB |
Output is correct |
32 |
Correct |
76 ms |
135288 KB |
Output is correct |
33 |
Correct |
76 ms |
135416 KB |
Output is correct |
34 |
Correct |
79 ms |
135160 KB |
Output is correct |
35 |
Correct |
78 ms |
135160 KB |
Output is correct |
36 |
Correct |
182 ms |
135292 KB |
Output is correct |
37 |
Correct |
126 ms |
135288 KB |
Output is correct |
38 |
Correct |
95 ms |
135160 KB |
Output is correct |
39 |
Correct |
125 ms |
135288 KB |
Output is correct |
40 |
Correct |
149 ms |
135160 KB |
Output is correct |
41 |
Correct |
95 ms |
135288 KB |
Output is correct |
42 |
Correct |
88 ms |
135288 KB |
Output is correct |
43 |
Correct |
93 ms |
135288 KB |
Output is correct |
44 |
Correct |
81 ms |
135160 KB |
Output is correct |
45 |
Correct |
95 ms |
135160 KB |
Output is correct |
46 |
Correct |
84 ms |
135160 KB |
Output is correct |
47 |
Correct |
93 ms |
135160 KB |
Output is correct |
48 |
Correct |
88 ms |
135416 KB |
Output is correct |
49 |
Correct |
93 ms |
135160 KB |
Output is correct |
50 |
Correct |
83 ms |
135160 KB |
Output is correct |
51 |
Correct |
91 ms |
135160 KB |
Output is correct |
52 |
Correct |
80 ms |
135160 KB |
Output is correct |
53 |
Correct |
93 ms |
135160 KB |
Output is correct |
54 |
Correct |
83 ms |
135288 KB |
Output is correct |
55 |
Correct |
100 ms |
135292 KB |
Output is correct |
56 |
Correct |
83 ms |
135160 KB |
Output is correct |
57 |
Correct |
102 ms |
135288 KB |
Output is correct |
58 |
Correct |
85 ms |
135160 KB |
Output is correct |
59 |
Correct |
228 ms |
135208 KB |
Output is correct |
60 |
Correct |
157 ms |
135160 KB |
Output is correct |
61 |
Correct |
222 ms |
135288 KB |
Output is correct |
62 |
Correct |
155 ms |
135288 KB |
Output is correct |
63 |
Correct |
222 ms |
135160 KB |
Output is correct |
64 |
Correct |
160 ms |
135160 KB |
Output is correct |
65 |
Correct |
197 ms |
135160 KB |
Output is correct |
66 |
Correct |
185 ms |
135288 KB |
Output is correct |
67 |
Correct |
172 ms |
135160 KB |
Output is correct |
68 |
Correct |
169 ms |
135160 KB |
Output is correct |
69 |
Correct |
202 ms |
135288 KB |
Output is correct |
70 |
Correct |
193 ms |
135160 KB |
Output is correct |
71 |
Correct |
192 ms |
135160 KB |
Output is correct |
72 |
Correct |
194 ms |
135416 KB |
Output is correct |
73 |
Correct |
182 ms |
135264 KB |
Output is correct |
74 |
Correct |
173 ms |
135160 KB |
Output is correct |
75 |
Correct |
191 ms |
135288 KB |
Output is correct |
76 |
Correct |
204 ms |
135160 KB |
Output is correct |
77 |
Correct |
213 ms |
135260 KB |
Output is correct |
78 |
Correct |
172 ms |
135292 KB |
Output is correct |
79 |
Correct |
166 ms |
135288 KB |
Output is correct |
80 |
Correct |
208 ms |
135288 KB |
Output is correct |
81 |
Correct |
169 ms |
135160 KB |
Output is correct |
82 |
Correct |
183 ms |
135288 KB |
Output is correct |
83 |
Correct |
226 ms |
135176 KB |
Output is correct |
84 |
Correct |
191 ms |
135288 KB |
Output is correct |
85 |
Correct |
206 ms |
135416 KB |
Output is correct |
86 |
Correct |
202 ms |
135288 KB |
Output is correct |
87 |
Correct |
186 ms |
135160 KB |
Output is correct |
88 |
Correct |
227 ms |
135160 KB |
Output is correct |
89 |
Correct |
231 ms |
135288 KB |
Output is correct |
90 |
Correct |
189 ms |
135288 KB |
Output is correct |
91 |
Correct |
215 ms |
135244 KB |
Output is correct |
92 |
Correct |
214 ms |
135160 KB |
Output is correct |
93 |
Correct |
218 ms |
135160 KB |
Output is correct |