#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define out(x) "{" << (#x) << ": " << x << "} "
const ll MAX_N = 410;
int dpLeft[MAX_N][MAX_N][MAX_N];
int dpRight[MAX_N][MAX_N][MAX_N];
int t[MAX_N], x[MAX_N], n, l;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
for(int i = 0; i < MAX_N; i ++) {
for(int j = 0; j < MAX_N; j ++) {
for(int k = 0; k < MAX_N; k ++) {
dpLeft[i][j][k] = dpRight[i][j][k] = mod;
}
}
}
cin >> n >> l;
for(int i = 0; i < n; i ++) {cin >> x[i]; x[n + i] = x[i] + l;}
for(int i = 0; i < n; i ++) {cin >> t[i]; t[n + i] = t[i];}
if(l - x[n - 1] <= t[n - 1]) {
dpLeft[n - 1][n - 1][1] = dpRight[n - 1][n - 1][1] = l - x[n - 1];
} else {
dpLeft[n - 1][n - 1][0] = dpRight[n - 1][n - 1][0] = l - x[n - 1];
}
if(x[n] - l <= t[n]) {
dpLeft[n][n][1] = dpRight[n][n][1] = x[n] - l;
} else {
dpLeft[n][n][0] = dpRight[n][n][0] = x[n] - l;
}
for(int len = 1; len <= n; len ++) {
for(int lft = 0; lft + len - 1 < 2 * n; lft ++) {
int rght = lft + len - 1;
///Go from left
for(int got = 0; got <= n; got ++) {
if(dpLeft[lft][rght][got] >= mod) {continue;}
int pos = x[lft];
if(lft != 0) {
int need = dpLeft[lft][rght][got] + pos - x[lft - 1];
bool canGet = need <= t[lft - 1];
chkmin(dpLeft[lft - 1][rght][got + canGet], need);
}
if(rght != 2 * n - 1) {
int need = dpLeft[lft][rght][got] + x[rght + 1] - pos;
bool canGet = need <= t[rght + 1];
chkmin(dpRight[lft][rght + 1][got + canGet], need);
}
}
///Go from right
for(int got = 0; got <= n; got ++) {
if(dpRight[lft][rght][got] >= mod) {continue;}
int pos = x[rght];
if(lft != 0) {
int need = dpRight[lft][rght][got] + pos - x[lft - 1];
bool canGet = need <= t[lft - 1];
chkmin(dpLeft[lft - 1][rght][got + canGet], need);
}
if(rght != 2 * n - 1) {
int need = dpRight[lft][rght][got] + x[rght + 1] - pos;
bool canGet = need <= t[rght + 1];
chkmin(dpRight[lft][rght + 1][got + canGet], need);
}
}
}
}
int ret = 0;
for(int i = 0; i <= n; i ++) {
for(int j = 0; j <= n; j ++) {
if(min(dpLeft[i][i + n - 1][j], dpRight[i][i + n - 1][j]) < mod) {
chkmax(ret, j);
}
}
}
cout << ret << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
539768 KB |
Output is correct |
2 |
Correct |
340 ms |
539872 KB |
Output is correct |
3 |
Correct |
329 ms |
539768 KB |
Output is correct |
4 |
Correct |
332 ms |
539768 KB |
Output is correct |
5 |
Correct |
336 ms |
539896 KB |
Output is correct |
6 |
Correct |
338 ms |
539896 KB |
Output is correct |
7 |
Correct |
335 ms |
539772 KB |
Output is correct |
8 |
Correct |
335 ms |
539768 KB |
Output is correct |
9 |
Correct |
331 ms |
539768 KB |
Output is correct |
10 |
Correct |
334 ms |
539768 KB |
Output is correct |
11 |
Correct |
336 ms |
539768 KB |
Output is correct |
12 |
Correct |
334 ms |
539896 KB |
Output is correct |
13 |
Correct |
333 ms |
539896 KB |
Output is correct |
14 |
Correct |
333 ms |
539896 KB |
Output is correct |
15 |
Correct |
335 ms |
539900 KB |
Output is correct |
16 |
Correct |
339 ms |
539768 KB |
Output is correct |
17 |
Correct |
338 ms |
539896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
539768 KB |
Output is correct |
2 |
Correct |
340 ms |
539872 KB |
Output is correct |
3 |
Correct |
329 ms |
539768 KB |
Output is correct |
4 |
Correct |
332 ms |
539768 KB |
Output is correct |
5 |
Correct |
336 ms |
539896 KB |
Output is correct |
6 |
Correct |
338 ms |
539896 KB |
Output is correct |
7 |
Correct |
335 ms |
539772 KB |
Output is correct |
8 |
Correct |
335 ms |
539768 KB |
Output is correct |
9 |
Correct |
331 ms |
539768 KB |
Output is correct |
10 |
Correct |
334 ms |
539768 KB |
Output is correct |
11 |
Correct |
336 ms |
539768 KB |
Output is correct |
12 |
Correct |
334 ms |
539896 KB |
Output is correct |
13 |
Correct |
333 ms |
539896 KB |
Output is correct |
14 |
Correct |
333 ms |
539896 KB |
Output is correct |
15 |
Correct |
335 ms |
539900 KB |
Output is correct |
16 |
Correct |
339 ms |
539768 KB |
Output is correct |
17 |
Correct |
338 ms |
539896 KB |
Output is correct |
18 |
Correct |
342 ms |
539800 KB |
Output is correct |
19 |
Correct |
336 ms |
539900 KB |
Output is correct |
20 |
Correct |
337 ms |
539768 KB |
Output is correct |
21 |
Correct |
335 ms |
539896 KB |
Output is correct |
22 |
Correct |
332 ms |
539768 KB |
Output is correct |
23 |
Correct |
330 ms |
539896 KB |
Output is correct |
24 |
Correct |
338 ms |
539820 KB |
Output is correct |
25 |
Correct |
335 ms |
539768 KB |
Output is correct |
26 |
Correct |
330 ms |
539896 KB |
Output is correct |
27 |
Correct |
331 ms |
540024 KB |
Output is correct |
28 |
Correct |
335 ms |
539772 KB |
Output is correct |
29 |
Correct |
332 ms |
539772 KB |
Output is correct |
30 |
Correct |
332 ms |
539896 KB |
Output is correct |
31 |
Correct |
332 ms |
539896 KB |
Output is correct |
32 |
Correct |
332 ms |
539900 KB |
Output is correct |
33 |
Correct |
329 ms |
539768 KB |
Output is correct |
34 |
Correct |
331 ms |
539896 KB |
Output is correct |
35 |
Correct |
333 ms |
539876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
539768 KB |
Output is correct |
2 |
Correct |
340 ms |
539872 KB |
Output is correct |
3 |
Correct |
329 ms |
539768 KB |
Output is correct |
4 |
Correct |
332 ms |
539768 KB |
Output is correct |
5 |
Correct |
336 ms |
539896 KB |
Output is correct |
6 |
Correct |
338 ms |
539896 KB |
Output is correct |
7 |
Correct |
335 ms |
539772 KB |
Output is correct |
8 |
Correct |
335 ms |
539768 KB |
Output is correct |
9 |
Correct |
331 ms |
539768 KB |
Output is correct |
10 |
Correct |
334 ms |
539768 KB |
Output is correct |
11 |
Correct |
336 ms |
539768 KB |
Output is correct |
12 |
Correct |
334 ms |
539896 KB |
Output is correct |
13 |
Correct |
333 ms |
539896 KB |
Output is correct |
14 |
Correct |
333 ms |
539896 KB |
Output is correct |
15 |
Correct |
335 ms |
539900 KB |
Output is correct |
16 |
Correct |
339 ms |
539768 KB |
Output is correct |
17 |
Correct |
338 ms |
539896 KB |
Output is correct |
18 |
Correct |
382 ms |
539808 KB |
Output is correct |
19 |
Correct |
354 ms |
539896 KB |
Output is correct |
20 |
Correct |
343 ms |
539900 KB |
Output is correct |
21 |
Correct |
355 ms |
539896 KB |
Output is correct |
22 |
Correct |
363 ms |
539896 KB |
Output is correct |
23 |
Correct |
345 ms |
539836 KB |
Output is correct |
24 |
Correct |
341 ms |
539896 KB |
Output is correct |
25 |
Correct |
344 ms |
539896 KB |
Output is correct |
26 |
Correct |
333 ms |
539768 KB |
Output is correct |
27 |
Correct |
349 ms |
540024 KB |
Output is correct |
28 |
Correct |
335 ms |
539768 KB |
Output is correct |
29 |
Correct |
344 ms |
540024 KB |
Output is correct |
30 |
Correct |
339 ms |
539896 KB |
Output is correct |
31 |
Correct |
343 ms |
539876 KB |
Output is correct |
32 |
Correct |
337 ms |
539896 KB |
Output is correct |
33 |
Correct |
343 ms |
539896 KB |
Output is correct |
34 |
Correct |
335 ms |
539852 KB |
Output is correct |
35 |
Correct |
338 ms |
539788 KB |
Output is correct |
36 |
Correct |
336 ms |
539896 KB |
Output is correct |
37 |
Correct |
340 ms |
539804 KB |
Output is correct |
38 |
Correct |
333 ms |
539896 KB |
Output is correct |
39 |
Correct |
351 ms |
539768 KB |
Output is correct |
40 |
Correct |
334 ms |
539768 KB |
Output is correct |
41 |
Correct |
403 ms |
539768 KB |
Output is correct |
42 |
Correct |
360 ms |
539768 KB |
Output is correct |
43 |
Correct |
405 ms |
539912 KB |
Output is correct |
44 |
Correct |
363 ms |
539896 KB |
Output is correct |
45 |
Correct |
395 ms |
539896 KB |
Output is correct |
46 |
Correct |
358 ms |
539768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
539768 KB |
Output is correct |
2 |
Correct |
340 ms |
539872 KB |
Output is correct |
3 |
Correct |
329 ms |
539768 KB |
Output is correct |
4 |
Correct |
332 ms |
539768 KB |
Output is correct |
5 |
Correct |
336 ms |
539896 KB |
Output is correct |
6 |
Correct |
338 ms |
539896 KB |
Output is correct |
7 |
Correct |
335 ms |
539772 KB |
Output is correct |
8 |
Correct |
335 ms |
539768 KB |
Output is correct |
9 |
Correct |
331 ms |
539768 KB |
Output is correct |
10 |
Correct |
334 ms |
539768 KB |
Output is correct |
11 |
Correct |
336 ms |
539768 KB |
Output is correct |
12 |
Correct |
334 ms |
539896 KB |
Output is correct |
13 |
Correct |
333 ms |
539896 KB |
Output is correct |
14 |
Correct |
333 ms |
539896 KB |
Output is correct |
15 |
Correct |
335 ms |
539900 KB |
Output is correct |
16 |
Correct |
339 ms |
539768 KB |
Output is correct |
17 |
Correct |
338 ms |
539896 KB |
Output is correct |
18 |
Correct |
342 ms |
539800 KB |
Output is correct |
19 |
Correct |
336 ms |
539900 KB |
Output is correct |
20 |
Correct |
337 ms |
539768 KB |
Output is correct |
21 |
Correct |
335 ms |
539896 KB |
Output is correct |
22 |
Correct |
332 ms |
539768 KB |
Output is correct |
23 |
Correct |
330 ms |
539896 KB |
Output is correct |
24 |
Correct |
338 ms |
539820 KB |
Output is correct |
25 |
Correct |
335 ms |
539768 KB |
Output is correct |
26 |
Correct |
330 ms |
539896 KB |
Output is correct |
27 |
Correct |
331 ms |
540024 KB |
Output is correct |
28 |
Correct |
335 ms |
539772 KB |
Output is correct |
29 |
Correct |
332 ms |
539772 KB |
Output is correct |
30 |
Correct |
332 ms |
539896 KB |
Output is correct |
31 |
Correct |
332 ms |
539896 KB |
Output is correct |
32 |
Correct |
332 ms |
539900 KB |
Output is correct |
33 |
Correct |
329 ms |
539768 KB |
Output is correct |
34 |
Correct |
331 ms |
539896 KB |
Output is correct |
35 |
Correct |
333 ms |
539876 KB |
Output is correct |
36 |
Correct |
382 ms |
539808 KB |
Output is correct |
37 |
Correct |
354 ms |
539896 KB |
Output is correct |
38 |
Correct |
343 ms |
539900 KB |
Output is correct |
39 |
Correct |
355 ms |
539896 KB |
Output is correct |
40 |
Correct |
363 ms |
539896 KB |
Output is correct |
41 |
Correct |
345 ms |
539836 KB |
Output is correct |
42 |
Correct |
341 ms |
539896 KB |
Output is correct |
43 |
Correct |
344 ms |
539896 KB |
Output is correct |
44 |
Correct |
333 ms |
539768 KB |
Output is correct |
45 |
Correct |
349 ms |
540024 KB |
Output is correct |
46 |
Correct |
335 ms |
539768 KB |
Output is correct |
47 |
Correct |
344 ms |
540024 KB |
Output is correct |
48 |
Correct |
339 ms |
539896 KB |
Output is correct |
49 |
Correct |
343 ms |
539876 KB |
Output is correct |
50 |
Correct |
337 ms |
539896 KB |
Output is correct |
51 |
Correct |
343 ms |
539896 KB |
Output is correct |
52 |
Correct |
335 ms |
539852 KB |
Output is correct |
53 |
Correct |
338 ms |
539788 KB |
Output is correct |
54 |
Correct |
336 ms |
539896 KB |
Output is correct |
55 |
Correct |
340 ms |
539804 KB |
Output is correct |
56 |
Correct |
333 ms |
539896 KB |
Output is correct |
57 |
Correct |
351 ms |
539768 KB |
Output is correct |
58 |
Correct |
334 ms |
539768 KB |
Output is correct |
59 |
Correct |
403 ms |
539768 KB |
Output is correct |
60 |
Correct |
360 ms |
539768 KB |
Output is correct |
61 |
Correct |
405 ms |
539912 KB |
Output is correct |
62 |
Correct |
363 ms |
539896 KB |
Output is correct |
63 |
Correct |
395 ms |
539896 KB |
Output is correct |
64 |
Correct |
358 ms |
539768 KB |
Output is correct |
65 |
Correct |
367 ms |
539908 KB |
Output is correct |
66 |
Correct |
367 ms |
539768 KB |
Output is correct |
67 |
Correct |
362 ms |
540040 KB |
Output is correct |
68 |
Correct |
361 ms |
539768 KB |
Output is correct |
69 |
Correct |
366 ms |
539896 KB |
Output is correct |
70 |
Correct |
366 ms |
539768 KB |
Output is correct |
71 |
Correct |
369 ms |
539896 KB |
Output is correct |
72 |
Correct |
369 ms |
539768 KB |
Output is correct |
73 |
Correct |
363 ms |
539780 KB |
Output is correct |
74 |
Correct |
360 ms |
539768 KB |
Output is correct |
75 |
Correct |
367 ms |
539824 KB |
Output is correct |
76 |
Correct |
376 ms |
539768 KB |
Output is correct |
77 |
Correct |
371 ms |
539896 KB |
Output is correct |
78 |
Correct |
367 ms |
539768 KB |
Output is correct |
79 |
Correct |
363 ms |
539768 KB |
Output is correct |
80 |
Correct |
380 ms |
539896 KB |
Output is correct |
81 |
Correct |
369 ms |
539896 KB |
Output is correct |
82 |
Correct |
372 ms |
539768 KB |
Output is correct |
83 |
Correct |
370 ms |
539884 KB |
Output is correct |
84 |
Correct |
372 ms |
539768 KB |
Output is correct |
85 |
Correct |
369 ms |
539860 KB |
Output is correct |
86 |
Correct |
375 ms |
539768 KB |
Output is correct |
87 |
Correct |
372 ms |
539896 KB |
Output is correct |
88 |
Correct |
375 ms |
539768 KB |
Output is correct |
89 |
Correct |
377 ms |
539768 KB |
Output is correct |
90 |
Correct |
363 ms |
539768 KB |
Output is correct |
91 |
Correct |
378 ms |
539768 KB |
Output is correct |
92 |
Correct |
377 ms |
539936 KB |
Output is correct |
93 |
Correct |
372 ms |
539768 KB |
Output is correct |