#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
using namespace std;
int ans = 0;
bool vis[400][400][2];
long long dp[400][400][201][2];
long long grid[400];
long long stamptime[400];
int nums; long long len;
int dplen, dp0len, dp00len;
void findans(int l, int r, int end) {
if (vis[l][r][end]) return;
vis[l][r][end] = true;
if (l==r) {
dp[l][l][0][end] = abs(len-grid[l]);
if (abs(len-grid[l]) <= stamptime[l])
dp[l][l][1][end] = abs(len-grid[l]);
} else if (end == 0) {
for (int i = l+1; i <= l+1; i++) {
findans(i, r, 0); findans(i, r, 1);
long distl = grid[i]-grid[l];
long distr = grid[r]-grid[l];
for (int j = 0; j < dp00len; j++) {
if (dp[i][r][j][0]+distl <= stamptime[l]) {
if (j != dp00len-1)
dp[l][r][j+1][0] = min(dp[l][r][j+1][0],
dp[i][r][j][0]+distl);
} else
dp[l][r][j][0] = min(dp[l][r][j][0],
dp[i][r][j][0]+distl);
if (dp[i][r][j][1]+distr <= stamptime[l]) {
if (j != dp00len-1)
dp[l][r][j+1][0] = min(dp[l][r][j+1][0],
dp[i][r][j][1]+distr);
} else
dp[l][r][j][0] = min(dp[l][r][j][0],
dp[i][r][j][1]+distr);
}
for (int j = dp00len-2; j >= 0; j--) {
dp[l][r][j][0] = min(dp[l][r][j][0],
dp[l][r][j+1][0]);
}
}
} else {
for (int i = r-1; i >= r-1; i--) {
findans(l, i, 0); findans(l, i, 1);
long distl = grid[r]-grid[l];
long distr = grid[r]-grid[i];
for (int j = 0; j < dp00len; j++) {
if (dp[l][i][j][0]+distl <= stamptime[r]) {
if (j != dp00len-1)
dp[l][r][j+1][1] = min(dp[l][r][j+1][1],
dp[l][i][j][0]+distl);
} else
dp[l][r][j][1] = min(dp[l][r][j][1],
dp[l][i][j][0]+distl);
if (dp[l][i][j][1]+distr <= stamptime[r]) {
if (j != dp00len-1)
dp[l][r][j+1][1] = min(dp[l][r][j+1][1],
dp[l][i][j][1]+distr);
} else
dp[l][r][j][1] = min(dp[l][r][j][1],
dp[l][i][j][1]+distr);
}
for (int j = dp00len-2; j >= 0; j--) {
dp[l][r][j][1] = min(dp[l][r][j][1],
dp[l][r][j+1][1]);
}
}
}
for (int i = 0; i < dp00len; i++) {
if (dp[l][r][i][end] != (((long long) 2*1e9)*3)) {
ans = max(ans, i);
}
}
}
int main() {
cin >> nums >> len;
dplen = nums*2; dp0len = nums*2; dp00len = nums+1;
for (int i = 0; i < nums; i++) {
int val; cin >> val;
grid[i] = val; grid[nums+i] = val+len;
}
for (int i = 0; i < nums; i++) {
int val; cin >> val;
stamptime[i] = val; stamptime[nums+i] = val;
}
for (int i = 0; i < dplen; i++) {
for (int j = 0; j < dp0len; j++) {
for (int k = 0; k < dp00len; k++) {
for (int l = 0; l < 2; l++) {
dp[i][j][k][l] = ((long long) 2*1e9)*3;
}
}
}
}
for (int i = 0; i <= nums; i++) {
findans(i, i+nums-1, 0);
findans(i, i+nums-1, 1);
}
cout << (ans) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
2 ms |
2284 KB |
Output is correct |
7 |
Correct |
2 ms |
1260 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
2 ms |
2284 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
2284 KB |
Output is correct |
13 |
Correct |
2 ms |
2284 KB |
Output is correct |
14 |
Correct |
1 ms |
1004 KB |
Output is correct |
15 |
Correct |
1 ms |
1260 KB |
Output is correct |
16 |
Correct |
2 ms |
2284 KB |
Output is correct |
17 |
Correct |
2 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
2 ms |
2284 KB |
Output is correct |
7 |
Correct |
2 ms |
1260 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
2 ms |
2284 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
2284 KB |
Output is correct |
13 |
Correct |
2 ms |
2284 KB |
Output is correct |
14 |
Correct |
1 ms |
1004 KB |
Output is correct |
15 |
Correct |
1 ms |
1260 KB |
Output is correct |
16 |
Correct |
2 ms |
2284 KB |
Output is correct |
17 |
Correct |
2 ms |
2284 KB |
Output is correct |
18 |
Correct |
2 ms |
2944 KB |
Output is correct |
19 |
Correct |
2 ms |
1644 KB |
Output is correct |
20 |
Correct |
2 ms |
2284 KB |
Output is correct |
21 |
Correct |
3 ms |
2924 KB |
Output is correct |
22 |
Correct |
2 ms |
1388 KB |
Output is correct |
23 |
Correct |
3 ms |
3308 KB |
Output is correct |
24 |
Correct |
2 ms |
2540 KB |
Output is correct |
25 |
Correct |
2 ms |
2924 KB |
Output is correct |
26 |
Correct |
3 ms |
2924 KB |
Output is correct |
27 |
Correct |
2 ms |
1260 KB |
Output is correct |
28 |
Correct |
2 ms |
1388 KB |
Output is correct |
29 |
Correct |
3 ms |
3308 KB |
Output is correct |
30 |
Correct |
3 ms |
3308 KB |
Output is correct |
31 |
Correct |
3 ms |
2924 KB |
Output is correct |
32 |
Correct |
3 ms |
2560 KB |
Output is correct |
33 |
Correct |
3 ms |
3308 KB |
Output is correct |
34 |
Correct |
3 ms |
3308 KB |
Output is correct |
35 |
Correct |
3 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
2 ms |
2284 KB |
Output is correct |
7 |
Correct |
2 ms |
1260 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
2 ms |
2284 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
2284 KB |
Output is correct |
13 |
Correct |
2 ms |
2284 KB |
Output is correct |
14 |
Correct |
1 ms |
1004 KB |
Output is correct |
15 |
Correct |
1 ms |
1260 KB |
Output is correct |
16 |
Correct |
2 ms |
2284 KB |
Output is correct |
17 |
Correct |
2 ms |
2284 KB |
Output is correct |
18 |
Correct |
363 ms |
405356 KB |
Output is correct |
19 |
Correct |
206 ms |
245100 KB |
Output is correct |
20 |
Correct |
113 ms |
129644 KB |
Output is correct |
21 |
Correct |
191 ms |
230980 KB |
Output is correct |
22 |
Correct |
258 ms |
300268 KB |
Output is correct |
23 |
Correct |
103 ms |
110060 KB |
Output is correct |
24 |
Correct |
62 ms |
85740 KB |
Output is correct |
25 |
Correct |
81 ms |
107628 KB |
Output is correct |
26 |
Correct |
27 ms |
40300 KB |
Output is correct |
27 |
Correct |
85 ms |
112492 KB |
Output is correct |
28 |
Correct |
57 ms |
79596 KB |
Output is correct |
29 |
Correct |
87 ms |
114796 KB |
Output is correct |
30 |
Correct |
69 ms |
89836 KB |
Output is correct |
31 |
Correct |
83 ms |
107756 KB |
Output is correct |
32 |
Correct |
40 ms |
55788 KB |
Output is correct |
33 |
Correct |
84 ms |
107628 KB |
Output is correct |
34 |
Correct |
26 ms |
37484 KB |
Output is correct |
35 |
Correct |
77 ms |
105324 KB |
Output is correct |
36 |
Correct |
36 ms |
49260 KB |
Output is correct |
37 |
Correct |
84 ms |
112364 KB |
Output is correct |
38 |
Correct |
43 ms |
60908 KB |
Output is correct |
39 |
Correct |
89 ms |
117356 KB |
Output is correct |
40 |
Correct |
48 ms |
68092 KB |
Output is correct |
41 |
Correct |
470 ms |
500844 KB |
Output is correct |
42 |
Correct |
291 ms |
336236 KB |
Output is correct |
43 |
Correct |
483 ms |
500844 KB |
Output is correct |
44 |
Correct |
285 ms |
332140 KB |
Output is correct |
45 |
Correct |
473 ms |
500844 KB |
Output is correct |
46 |
Correct |
302 ms |
336236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
2 ms |
2284 KB |
Output is correct |
7 |
Correct |
2 ms |
1260 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
2 ms |
2284 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
2284 KB |
Output is correct |
13 |
Correct |
2 ms |
2284 KB |
Output is correct |
14 |
Correct |
1 ms |
1004 KB |
Output is correct |
15 |
Correct |
1 ms |
1260 KB |
Output is correct |
16 |
Correct |
2 ms |
2284 KB |
Output is correct |
17 |
Correct |
2 ms |
2284 KB |
Output is correct |
18 |
Correct |
2 ms |
2944 KB |
Output is correct |
19 |
Correct |
2 ms |
1644 KB |
Output is correct |
20 |
Correct |
2 ms |
2284 KB |
Output is correct |
21 |
Correct |
3 ms |
2924 KB |
Output is correct |
22 |
Correct |
2 ms |
1388 KB |
Output is correct |
23 |
Correct |
3 ms |
3308 KB |
Output is correct |
24 |
Correct |
2 ms |
2540 KB |
Output is correct |
25 |
Correct |
2 ms |
2924 KB |
Output is correct |
26 |
Correct |
3 ms |
2924 KB |
Output is correct |
27 |
Correct |
2 ms |
1260 KB |
Output is correct |
28 |
Correct |
2 ms |
1388 KB |
Output is correct |
29 |
Correct |
3 ms |
3308 KB |
Output is correct |
30 |
Correct |
3 ms |
3308 KB |
Output is correct |
31 |
Correct |
3 ms |
2924 KB |
Output is correct |
32 |
Correct |
3 ms |
2560 KB |
Output is correct |
33 |
Correct |
3 ms |
3308 KB |
Output is correct |
34 |
Correct |
3 ms |
3308 KB |
Output is correct |
35 |
Correct |
3 ms |
3308 KB |
Output is correct |
36 |
Correct |
363 ms |
405356 KB |
Output is correct |
37 |
Correct |
206 ms |
245100 KB |
Output is correct |
38 |
Correct |
113 ms |
129644 KB |
Output is correct |
39 |
Correct |
191 ms |
230980 KB |
Output is correct |
40 |
Correct |
258 ms |
300268 KB |
Output is correct |
41 |
Correct |
103 ms |
110060 KB |
Output is correct |
42 |
Correct |
62 ms |
85740 KB |
Output is correct |
43 |
Correct |
81 ms |
107628 KB |
Output is correct |
44 |
Correct |
27 ms |
40300 KB |
Output is correct |
45 |
Correct |
85 ms |
112492 KB |
Output is correct |
46 |
Correct |
57 ms |
79596 KB |
Output is correct |
47 |
Correct |
87 ms |
114796 KB |
Output is correct |
48 |
Correct |
69 ms |
89836 KB |
Output is correct |
49 |
Correct |
83 ms |
107756 KB |
Output is correct |
50 |
Correct |
40 ms |
55788 KB |
Output is correct |
51 |
Correct |
84 ms |
107628 KB |
Output is correct |
52 |
Correct |
26 ms |
37484 KB |
Output is correct |
53 |
Correct |
77 ms |
105324 KB |
Output is correct |
54 |
Correct |
36 ms |
49260 KB |
Output is correct |
55 |
Correct |
84 ms |
112364 KB |
Output is correct |
56 |
Correct |
43 ms |
60908 KB |
Output is correct |
57 |
Correct |
89 ms |
117356 KB |
Output is correct |
58 |
Correct |
48 ms |
68092 KB |
Output is correct |
59 |
Correct |
470 ms |
500844 KB |
Output is correct |
60 |
Correct |
291 ms |
336236 KB |
Output is correct |
61 |
Correct |
483 ms |
500844 KB |
Output is correct |
62 |
Correct |
285 ms |
332140 KB |
Output is correct |
63 |
Correct |
473 ms |
500844 KB |
Output is correct |
64 |
Correct |
302 ms |
336236 KB |
Output is correct |
65 |
Correct |
410 ms |
451820 KB |
Output is correct |
66 |
Correct |
379 ms |
414444 KB |
Output is correct |
67 |
Correct |
354 ms |
396396 KB |
Output is correct |
68 |
Correct |
325 ms |
365676 KB |
Output is correct |
69 |
Correct |
410 ms |
446956 KB |
Output is correct |
70 |
Correct |
393 ms |
428268 KB |
Output is correct |
71 |
Correct |
400 ms |
433004 KB |
Output is correct |
72 |
Correct |
401 ms |
437612 KB |
Output is correct |
73 |
Correct |
410 ms |
405628 KB |
Output is correct |
74 |
Correct |
339 ms |
378732 KB |
Output is correct |
75 |
Correct |
393 ms |
419180 KB |
Output is correct |
76 |
Correct |
444 ms |
480876 KB |
Output is correct |
77 |
Correct |
446 ms |
480804 KB |
Output is correct |
78 |
Correct |
327 ms |
370156 KB |
Output is correct |
79 |
Correct |
339 ms |
383084 KB |
Output is correct |
80 |
Correct |
433 ms |
471020 KB |
Output is correct |
81 |
Correct |
344 ms |
387436 KB |
Output is correct |
82 |
Correct |
368 ms |
409836 KB |
Output is correct |
83 |
Correct |
470 ms |
500716 KB |
Output is correct |
84 |
Correct |
391 ms |
428268 KB |
Output is correct |
85 |
Correct |
426 ms |
466192 KB |
Output is correct |
86 |
Correct |
416 ms |
456556 KB |
Output is correct |
87 |
Correct |
376 ms |
419168 KB |
Output is correct |
88 |
Correct |
477 ms |
504172 KB |
Output is correct |
89 |
Correct |
470 ms |
504172 KB |
Output is correct |
90 |
Correct |
384 ms |
423660 KB |
Output is correct |
91 |
Correct |
492 ms |
504172 KB |
Output is correct |
92 |
Correct |
473 ms |
504172 KB |
Output is correct |
93 |
Correct |
458 ms |
495816 KB |
Output is correct |