//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 200 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;
int dp[N][N][N][2];
int n, x[N], L, T[N];
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> L;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= n; i++) cin >> T[i];
x[n + 1] = L;
memset(dp, 63, sizeof dp);
dp[0][0][0][0] = dp[0][0][0][1] = 0;
for (int i = 0; i <= n; i++){
for (int j = 0; j <= n - i - 1; j++){
for (int k = 0; k <= (i + j); k++){
//cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k][0] << ' ' << dp[i][j][k][1] << '\n';
int ti = dp[i][j][k][0];
if (ti + x[i + 1] - x[i] <= T[i + 1]) dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], ti + x[i + 1] - x[i]);
else dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], ti + x[i + 1] - x[i]);
//cout << ti + x[i] + L - x[n - j] << '\n';
if (ti + x[i] + L - x[n - j] <= T[n - j]) dp[i][j + 1][k + 1][1] = min(dp[i][j + 1][k + 1][1], ti + x[i] + L - x[n - j]);
else dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1], ti + x[i] + L - x[n - j]);
ti = dp[i][j][k][1];
if (ti + x[n - j + 1] - x[n - j] <= T[n - j]) dp[i][j + 1][k + 1][1] = min(dp[i][j + 1][k + 1][1], ti + x[n - j + 1] - x[n - j]);
else dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1], ti + x[n - j + 1] - x[n - j]);
if (L - x[n - j + 1] + ti + x[i + 1] <= T[i + 1]) dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], L - x[n - j + 1] + ti + x[i + 1]);
else dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], L - x[n - j + 1] + ti + x[i + 1]);
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++){
for (int j = 0; j <= n; j++){
if (min(dp[j][n - j][i][0], dp[j][n - j][i][1]) <= (1000000000000ll)) ans = i;
}
}
cout << ans;
return 0;
}
Compilation message
ho_t3.cpp:8:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
#pragma GCC optimise ("ofast")
ho_t3.cpp:9:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
#pragma GCC optimise("unroll-loops")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
145272 KB |
Output is correct |
2 |
Correct |
79 ms |
145400 KB |
Output is correct |
3 |
Correct |
79 ms |
145400 KB |
Output is correct |
4 |
Correct |
78 ms |
145276 KB |
Output is correct |
5 |
Correct |
79 ms |
145276 KB |
Output is correct |
6 |
Correct |
78 ms |
145400 KB |
Output is correct |
7 |
Correct |
83 ms |
145288 KB |
Output is correct |
8 |
Correct |
78 ms |
145272 KB |
Output is correct |
9 |
Correct |
79 ms |
145272 KB |
Output is correct |
10 |
Correct |
77 ms |
145272 KB |
Output is correct |
11 |
Correct |
81 ms |
145272 KB |
Output is correct |
12 |
Correct |
80 ms |
145272 KB |
Output is correct |
13 |
Correct |
79 ms |
145272 KB |
Output is correct |
14 |
Correct |
79 ms |
145400 KB |
Output is correct |
15 |
Correct |
78 ms |
145376 KB |
Output is correct |
16 |
Correct |
81 ms |
145272 KB |
Output is correct |
17 |
Correct |
81 ms |
145272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
145272 KB |
Output is correct |
2 |
Correct |
79 ms |
145400 KB |
Output is correct |
3 |
Correct |
79 ms |
145400 KB |
Output is correct |
4 |
Correct |
78 ms |
145276 KB |
Output is correct |
5 |
Correct |
79 ms |
145276 KB |
Output is correct |
6 |
Correct |
78 ms |
145400 KB |
Output is correct |
7 |
Correct |
83 ms |
145288 KB |
Output is correct |
8 |
Correct |
78 ms |
145272 KB |
Output is correct |
9 |
Correct |
79 ms |
145272 KB |
Output is correct |
10 |
Correct |
77 ms |
145272 KB |
Output is correct |
11 |
Correct |
81 ms |
145272 KB |
Output is correct |
12 |
Correct |
80 ms |
145272 KB |
Output is correct |
13 |
Correct |
79 ms |
145272 KB |
Output is correct |
14 |
Correct |
79 ms |
145400 KB |
Output is correct |
15 |
Correct |
78 ms |
145376 KB |
Output is correct |
16 |
Correct |
81 ms |
145272 KB |
Output is correct |
17 |
Correct |
81 ms |
145272 KB |
Output is correct |
18 |
Correct |
78 ms |
145272 KB |
Output is correct |
19 |
Correct |
81 ms |
145272 KB |
Output is correct |
20 |
Correct |
79 ms |
145272 KB |
Output is correct |
21 |
Correct |
79 ms |
145272 KB |
Output is correct |
22 |
Correct |
85 ms |
145272 KB |
Output is correct |
23 |
Correct |
81 ms |
145272 KB |
Output is correct |
24 |
Correct |
80 ms |
145396 KB |
Output is correct |
25 |
Correct |
81 ms |
145272 KB |
Output is correct |
26 |
Correct |
78 ms |
145272 KB |
Output is correct |
27 |
Correct |
82 ms |
145272 KB |
Output is correct |
28 |
Correct |
83 ms |
145400 KB |
Output is correct |
29 |
Correct |
77 ms |
145272 KB |
Output is correct |
30 |
Correct |
81 ms |
145272 KB |
Output is correct |
31 |
Correct |
79 ms |
145272 KB |
Output is correct |
32 |
Correct |
79 ms |
145272 KB |
Output is correct |
33 |
Correct |
80 ms |
145272 KB |
Output is correct |
34 |
Correct |
78 ms |
145272 KB |
Output is correct |
35 |
Correct |
78 ms |
145272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
145272 KB |
Output is correct |
2 |
Correct |
79 ms |
145400 KB |
Output is correct |
3 |
Correct |
79 ms |
145400 KB |
Output is correct |
4 |
Correct |
78 ms |
145276 KB |
Output is correct |
5 |
Correct |
79 ms |
145276 KB |
Output is correct |
6 |
Correct |
78 ms |
145400 KB |
Output is correct |
7 |
Correct |
83 ms |
145288 KB |
Output is correct |
8 |
Correct |
78 ms |
145272 KB |
Output is correct |
9 |
Correct |
79 ms |
145272 KB |
Output is correct |
10 |
Correct |
77 ms |
145272 KB |
Output is correct |
11 |
Correct |
81 ms |
145272 KB |
Output is correct |
12 |
Correct |
80 ms |
145272 KB |
Output is correct |
13 |
Correct |
79 ms |
145272 KB |
Output is correct |
14 |
Correct |
79 ms |
145400 KB |
Output is correct |
15 |
Correct |
78 ms |
145376 KB |
Output is correct |
16 |
Correct |
81 ms |
145272 KB |
Output is correct |
17 |
Correct |
81 ms |
145272 KB |
Output is correct |
18 |
Correct |
92 ms |
145272 KB |
Output is correct |
19 |
Correct |
88 ms |
145400 KB |
Output is correct |
20 |
Correct |
84 ms |
145272 KB |
Output is correct |
21 |
Correct |
86 ms |
145400 KB |
Output is correct |
22 |
Correct |
87 ms |
145272 KB |
Output is correct |
23 |
Correct |
80 ms |
145272 KB |
Output is correct |
24 |
Correct |
80 ms |
145272 KB |
Output is correct |
25 |
Correct |
83 ms |
145272 KB |
Output is correct |
26 |
Correct |
80 ms |
145400 KB |
Output is correct |
27 |
Correct |
79 ms |
145280 KB |
Output is correct |
28 |
Correct |
80 ms |
145400 KB |
Output is correct |
29 |
Correct |
81 ms |
145276 KB |
Output is correct |
30 |
Correct |
81 ms |
145332 KB |
Output is correct |
31 |
Correct |
84 ms |
145400 KB |
Output is correct |
32 |
Correct |
78 ms |
145272 KB |
Output is correct |
33 |
Correct |
82 ms |
145400 KB |
Output is correct |
34 |
Correct |
79 ms |
145272 KB |
Output is correct |
35 |
Correct |
87 ms |
145272 KB |
Output is correct |
36 |
Correct |
83 ms |
145272 KB |
Output is correct |
37 |
Correct |
117 ms |
145272 KB |
Output is correct |
38 |
Correct |
80 ms |
145272 KB |
Output is correct |
39 |
Correct |
83 ms |
145272 KB |
Output is correct |
40 |
Correct |
81 ms |
145272 KB |
Output is correct |
41 |
Correct |
99 ms |
145400 KB |
Output is correct |
42 |
Correct |
90 ms |
145400 KB |
Output is correct |
43 |
Correct |
97 ms |
145272 KB |
Output is correct |
44 |
Correct |
89 ms |
145272 KB |
Output is correct |
45 |
Correct |
99 ms |
145272 KB |
Output is correct |
46 |
Correct |
91 ms |
145400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
145272 KB |
Output is correct |
2 |
Correct |
79 ms |
145400 KB |
Output is correct |
3 |
Correct |
79 ms |
145400 KB |
Output is correct |
4 |
Correct |
78 ms |
145276 KB |
Output is correct |
5 |
Correct |
79 ms |
145276 KB |
Output is correct |
6 |
Correct |
78 ms |
145400 KB |
Output is correct |
7 |
Correct |
83 ms |
145288 KB |
Output is correct |
8 |
Correct |
78 ms |
145272 KB |
Output is correct |
9 |
Correct |
79 ms |
145272 KB |
Output is correct |
10 |
Correct |
77 ms |
145272 KB |
Output is correct |
11 |
Correct |
81 ms |
145272 KB |
Output is correct |
12 |
Correct |
80 ms |
145272 KB |
Output is correct |
13 |
Correct |
79 ms |
145272 KB |
Output is correct |
14 |
Correct |
79 ms |
145400 KB |
Output is correct |
15 |
Correct |
78 ms |
145376 KB |
Output is correct |
16 |
Correct |
81 ms |
145272 KB |
Output is correct |
17 |
Correct |
81 ms |
145272 KB |
Output is correct |
18 |
Correct |
78 ms |
145272 KB |
Output is correct |
19 |
Correct |
81 ms |
145272 KB |
Output is correct |
20 |
Correct |
79 ms |
145272 KB |
Output is correct |
21 |
Correct |
79 ms |
145272 KB |
Output is correct |
22 |
Correct |
85 ms |
145272 KB |
Output is correct |
23 |
Correct |
81 ms |
145272 KB |
Output is correct |
24 |
Correct |
80 ms |
145396 KB |
Output is correct |
25 |
Correct |
81 ms |
145272 KB |
Output is correct |
26 |
Correct |
78 ms |
145272 KB |
Output is correct |
27 |
Correct |
82 ms |
145272 KB |
Output is correct |
28 |
Correct |
83 ms |
145400 KB |
Output is correct |
29 |
Correct |
77 ms |
145272 KB |
Output is correct |
30 |
Correct |
81 ms |
145272 KB |
Output is correct |
31 |
Correct |
79 ms |
145272 KB |
Output is correct |
32 |
Correct |
79 ms |
145272 KB |
Output is correct |
33 |
Correct |
80 ms |
145272 KB |
Output is correct |
34 |
Correct |
78 ms |
145272 KB |
Output is correct |
35 |
Correct |
78 ms |
145272 KB |
Output is correct |
36 |
Correct |
92 ms |
145272 KB |
Output is correct |
37 |
Correct |
88 ms |
145400 KB |
Output is correct |
38 |
Correct |
84 ms |
145272 KB |
Output is correct |
39 |
Correct |
86 ms |
145400 KB |
Output is correct |
40 |
Correct |
87 ms |
145272 KB |
Output is correct |
41 |
Correct |
80 ms |
145272 KB |
Output is correct |
42 |
Correct |
80 ms |
145272 KB |
Output is correct |
43 |
Correct |
83 ms |
145272 KB |
Output is correct |
44 |
Correct |
80 ms |
145400 KB |
Output is correct |
45 |
Correct |
79 ms |
145280 KB |
Output is correct |
46 |
Correct |
80 ms |
145400 KB |
Output is correct |
47 |
Correct |
81 ms |
145276 KB |
Output is correct |
48 |
Correct |
81 ms |
145332 KB |
Output is correct |
49 |
Correct |
84 ms |
145400 KB |
Output is correct |
50 |
Correct |
78 ms |
145272 KB |
Output is correct |
51 |
Correct |
82 ms |
145400 KB |
Output is correct |
52 |
Correct |
79 ms |
145272 KB |
Output is correct |
53 |
Correct |
87 ms |
145272 KB |
Output is correct |
54 |
Correct |
83 ms |
145272 KB |
Output is correct |
55 |
Correct |
117 ms |
145272 KB |
Output is correct |
56 |
Correct |
80 ms |
145272 KB |
Output is correct |
57 |
Correct |
83 ms |
145272 KB |
Output is correct |
58 |
Correct |
81 ms |
145272 KB |
Output is correct |
59 |
Correct |
99 ms |
145400 KB |
Output is correct |
60 |
Correct |
90 ms |
145400 KB |
Output is correct |
61 |
Correct |
97 ms |
145272 KB |
Output is correct |
62 |
Correct |
89 ms |
145272 KB |
Output is correct |
63 |
Correct |
99 ms |
145272 KB |
Output is correct |
64 |
Correct |
91 ms |
145400 KB |
Output is correct |
65 |
Correct |
95 ms |
145272 KB |
Output is correct |
66 |
Correct |
94 ms |
145400 KB |
Output is correct |
67 |
Correct |
94 ms |
145272 KB |
Output is correct |
68 |
Correct |
92 ms |
145272 KB |
Output is correct |
69 |
Correct |
95 ms |
145272 KB |
Output is correct |
70 |
Correct |
93 ms |
145372 KB |
Output is correct |
71 |
Correct |
94 ms |
145272 KB |
Output is correct |
72 |
Correct |
94 ms |
145400 KB |
Output is correct |
73 |
Correct |
96 ms |
145500 KB |
Output is correct |
74 |
Correct |
91 ms |
145400 KB |
Output is correct |
75 |
Correct |
92 ms |
145344 KB |
Output is correct |
76 |
Correct |
100 ms |
145272 KB |
Output is correct |
77 |
Correct |
97 ms |
145340 KB |
Output is correct |
78 |
Correct |
90 ms |
145272 KB |
Output is correct |
79 |
Correct |
94 ms |
145272 KB |
Output is correct |
80 |
Correct |
93 ms |
145264 KB |
Output is correct |
81 |
Correct |
93 ms |
145272 KB |
Output is correct |
82 |
Correct |
95 ms |
145400 KB |
Output is correct |
83 |
Correct |
99 ms |
145368 KB |
Output is correct |
84 |
Correct |
91 ms |
145272 KB |
Output is correct |
85 |
Correct |
94 ms |
145272 KB |
Output is correct |
86 |
Correct |
95 ms |
145272 KB |
Output is correct |
87 |
Correct |
97 ms |
145528 KB |
Output is correct |
88 |
Correct |
96 ms |
145344 KB |
Output is correct |
89 |
Correct |
97 ms |
145272 KB |
Output is correct |
90 |
Correct |
93 ms |
145272 KB |
Output is correct |
91 |
Correct |
98 ms |
145272 KB |
Output is correct |
92 |
Correct |
98 ms |
145272 KB |
Output is correct |
93 |
Correct |
95 ms |
145272 KB |
Output is correct |