#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <numeric>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <ctime>
#include <chrono>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128_t int128;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const char en = '\n';
const int INF = 1e9 + 7;
const ll INFLL = 1e18;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
void solve() {
int n, L;
cin >> n >> L;
vector<ll> x(n + 1, 0), t(n + 1, -1);
for (int i = 1; i <= n; ++i) {
cin >> x[i];
}
for (int i = 1; i <= n; ++i) {
cin >> t[i];
}
int ans = 0;
vector<vector<vector<vector<int>>>> dp(n + 3,
vector<vector<vector<int>>> (n + 3,
vector<vector<int>> (2,
vector<int> (n + 3, INF))));
auto get_time = [&](int i, int j) {
i %= (n + 1);
j %= (n + 1);
ll dist = abs(x[i] - x[j]);
return min(dist, L - dist);
};
dp[0][0][0][0] = dp[0][0][1][0] = 0;
for (int len = 0; len <= n; ++len) {
for (int pref = 0; pref <= len; ++pref) {
int suf = len - pref;
for (int k = 0; k <= n; ++k) {
if (k == 1 && (dp[pref][suf][0][k] != INF || dp[pref][suf][1][k] != INF)) {
int kek = 0;
}
if (dp[pref][suf][0][k] != INF) {
int a = pref;
int go1 = a + 1, go2 = n + 1 - suf - 1;
if (1 <= go1 && go1 <= n && go1 != a) {
ll time = get_time(a, go1);
if (time + dp[pref][suf][0][k] <= t[go1] &&
time + dp[pref][suf][0][k] < dp[pref + 1][suf][0][k + 1]) {
dp[pref + 1][suf][0][k + 1] = time + dp[pref][suf][0][k];
} else if (time + dp[pref][suf][0][k] < dp[pref + 1][suf][0][k]) {
dp[pref + 1][suf][0][k] = time + dp[pref][suf][0][k];
}
}
if (1 <= go2 && go2 <= n && go2 != a) {
ll time = get_time(a, go2);
if (time + dp[pref][suf][0][k] <= t[go2] &&
time + dp[pref][suf][0][k] < dp[pref][suf + 1][1][k + 1]) {
dp[pref][suf + 1][1][k + 1] = time + dp[pref][suf][0][k];
} else if (time + dp[pref][suf][0][k] < dp[pref][suf + 1][1][k]) {
dp[pref][suf + 1][1][k] = time + dp[pref][suf][0][k];
}
}
}
if (dp[pref][suf][1][k] != INF) {
int a = (n + 1 - suf) % (n + 1);
int go1 = (a == 0 ? n : a - 1), go2 = pref + 1;
if (1 <= go1 && go1 <= n && go1 != a) {
ll time = get_time(a, go1);
if (time + dp[pref][suf][1][k] <= t[go1] &&
time + dp[pref][suf][1][k] < dp[pref][suf + 1][1][k + 1]) {
dp[pref][suf + 1][1][k + 1] = time + dp[pref][suf][1][k];
} else if (time + dp[pref][suf][1][k] < dp[pref][suf + 1][1][k]) {
dp[pref][suf + 1][1][k] = time + dp[pref][suf][1][k];
}
}
if (1 <= go2 && go2 <= n && go2 != a) {
ll time = get_time(a, go2);
if (time + dp[pref][suf][1][k] <= t[go2] &&
time + dp[pref][suf][1][k] < dp[pref + 1][suf][0][k + 1]) {
dp[pref + 1][suf][0][k + 1] = time + dp[pref][suf][1][k];
} else if (time + dp[pref][suf][1][k] < dp[pref + 1][suf][0][k]) {
dp[pref + 1][suf][0][k] = time + dp[pref][suf][1][k];
}
}
}
}
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
for (int k = 0; k <= 1; ++k) {
for (int cnt = 0; cnt <= n; ++cnt) {
if (i + j <= n && dp[i][j][k][cnt] != INF) {
// cerr << i << ' ' << j << ' ' << k << ' ' << cnt << endl;
ans = max(ans, cnt);
}
}
}
}
}
cout << ans << en;
}
int main() {
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
solve();
return 0;
}
Compilation message
ho_t3.cpp: In function 'void solve()':
ho_t3.cpp:70:25: warning: unused variable 'kek' [-Wunused-variable]
70 | int kek = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
324 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
101 ms |
51152 KB |
Output is correct |
19 |
Correct |
46 ms |
24952 KB |
Output is correct |
20 |
Correct |
18 ms |
10452 KB |
Output is correct |
21 |
Correct |
48 ms |
22956 KB |
Output is correct |
22 |
Correct |
63 ms |
33516 KB |
Output is correct |
23 |
Correct |
15 ms |
8404 KB |
Output is correct |
24 |
Correct |
8 ms |
5880 KB |
Output is correct |
25 |
Correct |
16 ms |
8148 KB |
Output is correct |
26 |
Correct |
3 ms |
2372 KB |
Output is correct |
27 |
Correct |
17 ms |
8584 KB |
Output is correct |
28 |
Correct |
7 ms |
5332 KB |
Output is correct |
29 |
Correct |
15 ms |
8660 KB |
Output is correct |
30 |
Correct |
8 ms |
6484 KB |
Output is correct |
31 |
Correct |
15 ms |
8160 KB |
Output is correct |
32 |
Correct |
6 ms |
3412 KB |
Output is correct |
33 |
Correct |
16 ms |
8148 KB |
Output is correct |
34 |
Correct |
3 ms |
2132 KB |
Output is correct |
35 |
Correct |
10 ms |
7764 KB |
Output is correct |
36 |
Correct |
5 ms |
2900 KB |
Output is correct |
37 |
Correct |
15 ms |
8584 KB |
Output is correct |
38 |
Correct |
7 ms |
3796 KB |
Output is correct |
39 |
Correct |
11 ms |
9244 KB |
Output is correct |
40 |
Correct |
6 ms |
4436 KB |
Output is correct |
41 |
Correct |
130 ms |
69328 KB |
Output is correct |
42 |
Correct |
44 ms |
39080 KB |
Output is correct |
43 |
Correct |
131 ms |
69324 KB |
Output is correct |
44 |
Correct |
39 ms |
38604 KB |
Output is correct |
45 |
Correct |
138 ms |
69328 KB |
Output is correct |
46 |
Correct |
39 ms |
39124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
324 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
101 ms |
51152 KB |
Output is correct |
37 |
Correct |
46 ms |
24952 KB |
Output is correct |
38 |
Correct |
18 ms |
10452 KB |
Output is correct |
39 |
Correct |
48 ms |
22956 KB |
Output is correct |
40 |
Correct |
63 ms |
33516 KB |
Output is correct |
41 |
Correct |
15 ms |
8404 KB |
Output is correct |
42 |
Correct |
8 ms |
5880 KB |
Output is correct |
43 |
Correct |
16 ms |
8148 KB |
Output is correct |
44 |
Correct |
3 ms |
2372 KB |
Output is correct |
45 |
Correct |
17 ms |
8584 KB |
Output is correct |
46 |
Correct |
7 ms |
5332 KB |
Output is correct |
47 |
Correct |
15 ms |
8660 KB |
Output is correct |
48 |
Correct |
8 ms |
6484 KB |
Output is correct |
49 |
Correct |
15 ms |
8160 KB |
Output is correct |
50 |
Correct |
6 ms |
3412 KB |
Output is correct |
51 |
Correct |
16 ms |
8148 KB |
Output is correct |
52 |
Correct |
3 ms |
2132 KB |
Output is correct |
53 |
Correct |
10 ms |
7764 KB |
Output is correct |
54 |
Correct |
5 ms |
2900 KB |
Output is correct |
55 |
Correct |
15 ms |
8584 KB |
Output is correct |
56 |
Correct |
7 ms |
3796 KB |
Output is correct |
57 |
Correct |
11 ms |
9244 KB |
Output is correct |
58 |
Correct |
6 ms |
4436 KB |
Output is correct |
59 |
Correct |
130 ms |
69328 KB |
Output is correct |
60 |
Correct |
44 ms |
39080 KB |
Output is correct |
61 |
Correct |
131 ms |
69324 KB |
Output is correct |
62 |
Correct |
39 ms |
38604 KB |
Output is correct |
63 |
Correct |
138 ms |
69328 KB |
Output is correct |
64 |
Correct |
39 ms |
39124 KB |
Output is correct |
65 |
Correct |
59 ms |
60360 KB |
Output is correct |
66 |
Correct |
57 ms |
53340 KB |
Output is correct |
67 |
Correct |
50 ms |
50012 KB |
Output is correct |
68 |
Correct |
46 ms |
44348 KB |
Output is correct |
69 |
Correct |
68 ms |
59740 KB |
Output is correct |
70 |
Correct |
74 ms |
56184 KB |
Output is correct |
71 |
Correct |
55 ms |
56784 KB |
Output is correct |
72 |
Correct |
72 ms |
57384 KB |
Output is correct |
73 |
Correct |
56 ms |
51140 KB |
Output is correct |
74 |
Correct |
61 ms |
46796 KB |
Output is correct |
75 |
Correct |
49 ms |
53836 KB |
Output is correct |
76 |
Correct |
143 ms |
65392 KB |
Output is correct |
77 |
Correct |
61 ms |
65396 KB |
Output is correct |
78 |
Correct |
82 ms |
44900 KB |
Output is correct |
79 |
Correct |
46 ms |
47324 KB |
Output is correct |
80 |
Correct |
116 ms |
64092 KB |
Output is correct |
81 |
Correct |
46 ms |
47952 KB |
Output is correct |
82 |
Correct |
73 ms |
52772 KB |
Output is correct |
83 |
Correct |
65 ms |
69336 KB |
Output is correct |
84 |
Correct |
84 ms |
56184 KB |
Output is correct |
85 |
Correct |
82 ms |
63444 KB |
Output is correct |
86 |
Correct |
89 ms |
60992 KB |
Output is correct |
87 |
Correct |
56 ms |
53920 KB |
Output is correct |
88 |
Correct |
89 ms |
71252 KB |
Output is correct |
89 |
Correct |
68 ms |
71300 KB |
Output is correct |
90 |
Correct |
49 ms |
54484 KB |
Output is correct |
91 |
Correct |
88 ms |
71292 KB |
Output is correct |
92 |
Correct |
69 ms |
71260 KB |
Output is correct |
93 |
Correct |
61 ms |
68580 KB |
Output is correct |