#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 9;
const ll LOGN = 21;
const ll MAXN = 1e6 + 100;
#define int long long
vector<int> X, T;
int dp[205][205][205][2], N, L;
int find_dist(int i, int j) {
if (i != N + 1 && j != 0)
return min(abs(X[j] - X[i]), L - abs(X[j] - X[i]));
if (i == N + 1)
return min(X[j], L - X[j]);
if (j == 0)
return min(X[i], L - X[i]);
}
signed main() {
fast
cin >> N >> L;
X = vector<int>(N+1);
T = vector<int>(N+1);
for (int i = 1; i <= N; i++)
cin >> X[i];
for (int i = 1; i <= N; i++)
cin >> T[i];
for (int i = 0; i < 205; i++) {
for (int j = 0; j < 205; j++) {
for (int k = 0; k < 205; k++)
dp[i][j][k][0] = dp[i][j][k][1] = 1e15;
}
}
dp[0][0][0][0] = dp[0][0][0][1] = 0;
int ans = 0;
for (int l = 0; l <= N; l++) {
for (int r = 0; r <= N; r++) {
if (l + r >= N)
continue;
for (int cnt = 0; cnt <= N; cnt++) {
// solda bulunuyor
int x = dp[cnt][l][r][0] + find_dist(N - l + 1, N - l);
if (x < dp[cnt + (x <= T[N-l])][l+1][r][0]) {
dp[cnt + (x <= T[N-l])][l+1][r][0] = x;
ans = max(ans, cnt + (x <= T[N-l]));
}
x = dp[cnt][l][r][0] + find_dist(N - l + 1, r + 1);
if (x < dp[cnt + (x <= T[r+1])][l][r+1][1]) {
dp[cnt + (x <= T[r+1])][l][r+1][1] = x;
ans = max(ans, cnt + (x <= T[r+1]));
}
// sağda bulunuyor
x = dp[cnt][l][r][1] + find_dist(N - l, r);
if (x < dp[cnt + (x <= T[N-l])][l+1][r][0]) {
dp[cnt + (x <= T[N-l])][l+1][r][0] = x;
ans = max(ans, cnt + (x <= T[N-l]));
}
x = dp[cnt][l][r][1] + find_dist(r, r + 1);
if (x < dp[cnt + (x <= T[r+1])][l][r+1][1]) {
dp[cnt + (x <= T[r+1])][l][r+1][1] = x;
ans = max(ans, cnt + (x <= T[r+1]));
}
}
}
}
cout << ans << "\n";
}
Compilation message
ho_t3.cpp: In function 'long long int find_dist(long long int, long long int)':
ho_t3.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
22 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
135260 KB |
Output is correct |
2 |
Correct |
46 ms |
135236 KB |
Output is correct |
3 |
Correct |
49 ms |
135256 KB |
Output is correct |
4 |
Correct |
43 ms |
135144 KB |
Output is correct |
5 |
Correct |
46 ms |
135252 KB |
Output is correct |
6 |
Correct |
44 ms |
135248 KB |
Output is correct |
7 |
Correct |
43 ms |
135252 KB |
Output is correct |
8 |
Correct |
43 ms |
135260 KB |
Output is correct |
9 |
Correct |
40 ms |
135056 KB |
Output is correct |
10 |
Correct |
39 ms |
135300 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
38 ms |
135248 KB |
Output is correct |
13 |
Correct |
39 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135056 KB |
Output is correct |
15 |
Correct |
39 ms |
135512 KB |
Output is correct |
16 |
Correct |
39 ms |
135252 KB |
Output is correct |
17 |
Correct |
39 ms |
135108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
135260 KB |
Output is correct |
2 |
Correct |
46 ms |
135236 KB |
Output is correct |
3 |
Correct |
49 ms |
135256 KB |
Output is correct |
4 |
Correct |
43 ms |
135144 KB |
Output is correct |
5 |
Correct |
46 ms |
135252 KB |
Output is correct |
6 |
Correct |
44 ms |
135248 KB |
Output is correct |
7 |
Correct |
43 ms |
135252 KB |
Output is correct |
8 |
Correct |
43 ms |
135260 KB |
Output is correct |
9 |
Correct |
40 ms |
135056 KB |
Output is correct |
10 |
Correct |
39 ms |
135300 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
38 ms |
135248 KB |
Output is correct |
13 |
Correct |
39 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135056 KB |
Output is correct |
15 |
Correct |
39 ms |
135512 KB |
Output is correct |
16 |
Correct |
39 ms |
135252 KB |
Output is correct |
17 |
Correct |
39 ms |
135108 KB |
Output is correct |
18 |
Correct |
44 ms |
135212 KB |
Output is correct |
19 |
Correct |
40 ms |
135268 KB |
Output is correct |
20 |
Correct |
40 ms |
135256 KB |
Output is correct |
21 |
Correct |
40 ms |
135308 KB |
Output is correct |
22 |
Correct |
39 ms |
135248 KB |
Output is correct |
23 |
Correct |
40 ms |
135260 KB |
Output is correct |
24 |
Correct |
43 ms |
135452 KB |
Output is correct |
25 |
Correct |
40 ms |
135164 KB |
Output is correct |
26 |
Correct |
40 ms |
135256 KB |
Output is correct |
27 |
Correct |
40 ms |
135152 KB |
Output is correct |
28 |
Correct |
39 ms |
135260 KB |
Output is correct |
29 |
Correct |
40 ms |
135260 KB |
Output is correct |
30 |
Correct |
40 ms |
135264 KB |
Output is correct |
31 |
Correct |
49 ms |
135120 KB |
Output is correct |
32 |
Correct |
44 ms |
135356 KB |
Output is correct |
33 |
Correct |
39 ms |
135260 KB |
Output is correct |
34 |
Correct |
47 ms |
135084 KB |
Output is correct |
35 |
Correct |
39 ms |
135252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
135260 KB |
Output is correct |
2 |
Correct |
46 ms |
135236 KB |
Output is correct |
3 |
Correct |
49 ms |
135256 KB |
Output is correct |
4 |
Correct |
43 ms |
135144 KB |
Output is correct |
5 |
Correct |
46 ms |
135252 KB |
Output is correct |
6 |
Correct |
44 ms |
135248 KB |
Output is correct |
7 |
Correct |
43 ms |
135252 KB |
Output is correct |
8 |
Correct |
43 ms |
135260 KB |
Output is correct |
9 |
Correct |
40 ms |
135056 KB |
Output is correct |
10 |
Correct |
39 ms |
135300 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
38 ms |
135248 KB |
Output is correct |
13 |
Correct |
39 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135056 KB |
Output is correct |
15 |
Correct |
39 ms |
135512 KB |
Output is correct |
16 |
Correct |
39 ms |
135252 KB |
Output is correct |
17 |
Correct |
39 ms |
135108 KB |
Output is correct |
18 |
Correct |
98 ms |
135252 KB |
Output is correct |
19 |
Correct |
64 ms |
135244 KB |
Output is correct |
20 |
Correct |
48 ms |
135248 KB |
Output is correct |
21 |
Correct |
59 ms |
135252 KB |
Output is correct |
22 |
Correct |
74 ms |
135312 KB |
Output is correct |
23 |
Correct |
46 ms |
135248 KB |
Output is correct |
24 |
Correct |
42 ms |
135248 KB |
Output is correct |
25 |
Correct |
44 ms |
135248 KB |
Output is correct |
26 |
Correct |
39 ms |
135260 KB |
Output is correct |
27 |
Correct |
45 ms |
135088 KB |
Output is correct |
28 |
Correct |
42 ms |
135184 KB |
Output is correct |
29 |
Correct |
46 ms |
135256 KB |
Output is correct |
30 |
Correct |
43 ms |
135272 KB |
Output is correct |
31 |
Correct |
47 ms |
135252 KB |
Output is correct |
32 |
Correct |
40 ms |
135260 KB |
Output is correct |
33 |
Correct |
45 ms |
135096 KB |
Output is correct |
34 |
Correct |
39 ms |
135284 KB |
Output is correct |
35 |
Correct |
46 ms |
135260 KB |
Output is correct |
36 |
Correct |
40 ms |
135260 KB |
Output is correct |
37 |
Correct |
46 ms |
135176 KB |
Output is correct |
38 |
Correct |
40 ms |
135252 KB |
Output is correct |
39 |
Correct |
45 ms |
135252 KB |
Output is correct |
40 |
Correct |
41 ms |
135192 KB |
Output is correct |
41 |
Correct |
106 ms |
135248 KB |
Output is correct |
42 |
Correct |
71 ms |
135248 KB |
Output is correct |
43 |
Correct |
113 ms |
135308 KB |
Output is correct |
44 |
Correct |
72 ms |
135312 KB |
Output is correct |
45 |
Correct |
105 ms |
135296 KB |
Output is correct |
46 |
Correct |
77 ms |
135252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
135260 KB |
Output is correct |
2 |
Correct |
46 ms |
135236 KB |
Output is correct |
3 |
Correct |
49 ms |
135256 KB |
Output is correct |
4 |
Correct |
43 ms |
135144 KB |
Output is correct |
5 |
Correct |
46 ms |
135252 KB |
Output is correct |
6 |
Correct |
44 ms |
135248 KB |
Output is correct |
7 |
Correct |
43 ms |
135252 KB |
Output is correct |
8 |
Correct |
43 ms |
135260 KB |
Output is correct |
9 |
Correct |
40 ms |
135056 KB |
Output is correct |
10 |
Correct |
39 ms |
135300 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
38 ms |
135248 KB |
Output is correct |
13 |
Correct |
39 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135056 KB |
Output is correct |
15 |
Correct |
39 ms |
135512 KB |
Output is correct |
16 |
Correct |
39 ms |
135252 KB |
Output is correct |
17 |
Correct |
39 ms |
135108 KB |
Output is correct |
18 |
Correct |
44 ms |
135212 KB |
Output is correct |
19 |
Correct |
40 ms |
135268 KB |
Output is correct |
20 |
Correct |
40 ms |
135256 KB |
Output is correct |
21 |
Correct |
40 ms |
135308 KB |
Output is correct |
22 |
Correct |
39 ms |
135248 KB |
Output is correct |
23 |
Correct |
40 ms |
135260 KB |
Output is correct |
24 |
Correct |
43 ms |
135452 KB |
Output is correct |
25 |
Correct |
40 ms |
135164 KB |
Output is correct |
26 |
Correct |
40 ms |
135256 KB |
Output is correct |
27 |
Correct |
40 ms |
135152 KB |
Output is correct |
28 |
Correct |
39 ms |
135260 KB |
Output is correct |
29 |
Correct |
40 ms |
135260 KB |
Output is correct |
30 |
Correct |
40 ms |
135264 KB |
Output is correct |
31 |
Correct |
49 ms |
135120 KB |
Output is correct |
32 |
Correct |
44 ms |
135356 KB |
Output is correct |
33 |
Correct |
39 ms |
135260 KB |
Output is correct |
34 |
Correct |
47 ms |
135084 KB |
Output is correct |
35 |
Correct |
39 ms |
135252 KB |
Output is correct |
36 |
Correct |
98 ms |
135252 KB |
Output is correct |
37 |
Correct |
64 ms |
135244 KB |
Output is correct |
38 |
Correct |
48 ms |
135248 KB |
Output is correct |
39 |
Correct |
59 ms |
135252 KB |
Output is correct |
40 |
Correct |
74 ms |
135312 KB |
Output is correct |
41 |
Correct |
46 ms |
135248 KB |
Output is correct |
42 |
Correct |
42 ms |
135248 KB |
Output is correct |
43 |
Correct |
44 ms |
135248 KB |
Output is correct |
44 |
Correct |
39 ms |
135260 KB |
Output is correct |
45 |
Correct |
45 ms |
135088 KB |
Output is correct |
46 |
Correct |
42 ms |
135184 KB |
Output is correct |
47 |
Correct |
46 ms |
135256 KB |
Output is correct |
48 |
Correct |
43 ms |
135272 KB |
Output is correct |
49 |
Correct |
47 ms |
135252 KB |
Output is correct |
50 |
Correct |
40 ms |
135260 KB |
Output is correct |
51 |
Correct |
45 ms |
135096 KB |
Output is correct |
52 |
Correct |
39 ms |
135284 KB |
Output is correct |
53 |
Correct |
46 ms |
135260 KB |
Output is correct |
54 |
Correct |
40 ms |
135260 KB |
Output is correct |
55 |
Correct |
46 ms |
135176 KB |
Output is correct |
56 |
Correct |
40 ms |
135252 KB |
Output is correct |
57 |
Correct |
45 ms |
135252 KB |
Output is correct |
58 |
Correct |
41 ms |
135192 KB |
Output is correct |
59 |
Correct |
106 ms |
135248 KB |
Output is correct |
60 |
Correct |
71 ms |
135248 KB |
Output is correct |
61 |
Correct |
113 ms |
135308 KB |
Output is correct |
62 |
Correct |
72 ms |
135312 KB |
Output is correct |
63 |
Correct |
105 ms |
135296 KB |
Output is correct |
64 |
Correct |
77 ms |
135252 KB |
Output is correct |
65 |
Correct |
105 ms |
135276 KB |
Output is correct |
66 |
Correct |
89 ms |
135252 KB |
Output is correct |
67 |
Correct |
88 ms |
135312 KB |
Output is correct |
68 |
Correct |
84 ms |
135320 KB |
Output is correct |
69 |
Correct |
100 ms |
135508 KB |
Output is correct |
70 |
Correct |
98 ms |
135156 KB |
Output is correct |
71 |
Correct |
92 ms |
135312 KB |
Output is correct |
72 |
Correct |
97 ms |
135316 KB |
Output is correct |
73 |
Correct |
89 ms |
135260 KB |
Output is correct |
74 |
Correct |
80 ms |
135256 KB |
Output is correct |
75 |
Correct |
89 ms |
135248 KB |
Output is correct |
76 |
Correct |
107 ms |
135088 KB |
Output is correct |
77 |
Correct |
97 ms |
135312 KB |
Output is correct |
78 |
Correct |
88 ms |
135508 KB |
Output is correct |
79 |
Correct |
88 ms |
135260 KB |
Output is correct |
80 |
Correct |
101 ms |
135260 KB |
Output is correct |
81 |
Correct |
86 ms |
135248 KB |
Output is correct |
82 |
Correct |
84 ms |
135248 KB |
Output is correct |
83 |
Correct |
104 ms |
135256 KB |
Output is correct |
84 |
Correct |
88 ms |
135316 KB |
Output is correct |
85 |
Correct |
97 ms |
135316 KB |
Output is correct |
86 |
Correct |
92 ms |
135204 KB |
Output is correct |
87 |
Correct |
91 ms |
135312 KB |
Output is correct |
88 |
Correct |
113 ms |
135252 KB |
Output is correct |
89 |
Correct |
105 ms |
135252 KB |
Output is correct |
90 |
Correct |
87 ms |
135316 KB |
Output is correct |
91 |
Correct |
112 ms |
135316 KB |
Output is correct |
92 |
Correct |
110 ms |
135312 KB |
Output is correct |
93 |
Correct |
97 ms |
135248 KB |
Output is correct |