#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MIN(a, b) a = min(a, b)
int n, L, ans, A[205], T[205]; int dp[205][205][205][2];
int main(){
cin >> n >> L;
FOR(i, 0, n) cin >> A[i];
FOR(i, 0, n) cin >> T[i];
auto dst = [&](int a, int b){ return min(abs(a - b), L - abs(a - b)); };
memset(dp, 0x3f, sizeof(dp));
for (int i = 0; i < n; i++){
bool ok = (dst(0, A[i]) <= T[i]);
dp[ok][i][i][0] = dp[ok][i][i][1] = dst(0, A[i]);
}
FOR(x, 1, n + 1)
FOR(sz, 1, n + 1)
for (int a = 0, b = sz - 1, flag = 1; a or flag; a = (a + 1) % n, b = (b + 1) % n, flag = 0)
FOR(pos, 0, 2){
int &curT = dp[x][a][b][pos], curP = !pos ? a : b;
int nxA = (a - 1 + n) % n, nxB = (b + 1) % n;
if (curT <= 1e9) ans = x;
if (curT > 1e9 or sz == n) continue;
int newT1 = curT + dst(A[curP], A[nxA]), use1 = x + (newT1 <= T[nxA]);
MIN(dp[use1][nxA][b][0], newT1);
int newT2 = curT + dst(A[curP], A[nxB]), use2 = x + (newT2 <= T[nxB]);
MIN(dp[use2][a][nxB][1], newT2);
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
67660 KB |
Output is correct |
2 |
Correct |
27 ms |
67616 KB |
Output is correct |
3 |
Correct |
26 ms |
67660 KB |
Output is correct |
4 |
Correct |
25 ms |
67612 KB |
Output is correct |
5 |
Correct |
25 ms |
67688 KB |
Output is correct |
6 |
Correct |
24 ms |
67676 KB |
Output is correct |
7 |
Correct |
25 ms |
67652 KB |
Output is correct |
8 |
Correct |
24 ms |
67676 KB |
Output is correct |
9 |
Correct |
24 ms |
67648 KB |
Output is correct |
10 |
Correct |
25 ms |
67720 KB |
Output is correct |
11 |
Correct |
25 ms |
67644 KB |
Output is correct |
12 |
Correct |
26 ms |
67688 KB |
Output is correct |
13 |
Correct |
24 ms |
67732 KB |
Output is correct |
14 |
Correct |
24 ms |
67660 KB |
Output is correct |
15 |
Correct |
24 ms |
67660 KB |
Output is correct |
16 |
Correct |
24 ms |
67684 KB |
Output is correct |
17 |
Correct |
28 ms |
67644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
67660 KB |
Output is correct |
2 |
Correct |
27 ms |
67616 KB |
Output is correct |
3 |
Correct |
26 ms |
67660 KB |
Output is correct |
4 |
Correct |
25 ms |
67612 KB |
Output is correct |
5 |
Correct |
25 ms |
67688 KB |
Output is correct |
6 |
Correct |
24 ms |
67676 KB |
Output is correct |
7 |
Correct |
25 ms |
67652 KB |
Output is correct |
8 |
Correct |
24 ms |
67676 KB |
Output is correct |
9 |
Correct |
24 ms |
67648 KB |
Output is correct |
10 |
Correct |
25 ms |
67720 KB |
Output is correct |
11 |
Correct |
25 ms |
67644 KB |
Output is correct |
12 |
Correct |
26 ms |
67688 KB |
Output is correct |
13 |
Correct |
24 ms |
67732 KB |
Output is correct |
14 |
Correct |
24 ms |
67660 KB |
Output is correct |
15 |
Correct |
24 ms |
67660 KB |
Output is correct |
16 |
Correct |
24 ms |
67684 KB |
Output is correct |
17 |
Correct |
28 ms |
67644 KB |
Output is correct |
18 |
Correct |
24 ms |
67660 KB |
Output is correct |
19 |
Correct |
23 ms |
67652 KB |
Output is correct |
20 |
Correct |
25 ms |
67616 KB |
Output is correct |
21 |
Correct |
25 ms |
67624 KB |
Output is correct |
22 |
Correct |
26 ms |
67596 KB |
Output is correct |
23 |
Correct |
28 ms |
67652 KB |
Output is correct |
24 |
Correct |
24 ms |
67660 KB |
Output is correct |
25 |
Correct |
25 ms |
67632 KB |
Output is correct |
26 |
Correct |
24 ms |
67660 KB |
Output is correct |
27 |
Correct |
26 ms |
67684 KB |
Output is correct |
28 |
Correct |
25 ms |
67684 KB |
Output is correct |
29 |
Correct |
24 ms |
67728 KB |
Output is correct |
30 |
Correct |
27 ms |
67612 KB |
Output is correct |
31 |
Correct |
25 ms |
67660 KB |
Output is correct |
32 |
Correct |
25 ms |
67628 KB |
Output is correct |
33 |
Correct |
25 ms |
67732 KB |
Output is correct |
34 |
Correct |
24 ms |
67660 KB |
Output is correct |
35 |
Correct |
25 ms |
67724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
67660 KB |
Output is correct |
2 |
Correct |
27 ms |
67616 KB |
Output is correct |
3 |
Correct |
26 ms |
67660 KB |
Output is correct |
4 |
Correct |
25 ms |
67612 KB |
Output is correct |
5 |
Correct |
25 ms |
67688 KB |
Output is correct |
6 |
Correct |
24 ms |
67676 KB |
Output is correct |
7 |
Correct |
25 ms |
67652 KB |
Output is correct |
8 |
Correct |
24 ms |
67676 KB |
Output is correct |
9 |
Correct |
24 ms |
67648 KB |
Output is correct |
10 |
Correct |
25 ms |
67720 KB |
Output is correct |
11 |
Correct |
25 ms |
67644 KB |
Output is correct |
12 |
Correct |
26 ms |
67688 KB |
Output is correct |
13 |
Correct |
24 ms |
67732 KB |
Output is correct |
14 |
Correct |
24 ms |
67660 KB |
Output is correct |
15 |
Correct |
24 ms |
67660 KB |
Output is correct |
16 |
Correct |
24 ms |
67684 KB |
Output is correct |
17 |
Correct |
28 ms |
67644 KB |
Output is correct |
18 |
Correct |
151 ms |
67660 KB |
Output is correct |
19 |
Correct |
89 ms |
67704 KB |
Output is correct |
20 |
Correct |
52 ms |
67660 KB |
Output is correct |
21 |
Correct |
89 ms |
67776 KB |
Output is correct |
22 |
Correct |
110 ms |
67708 KB |
Output is correct |
23 |
Correct |
48 ms |
67660 KB |
Output is correct |
24 |
Correct |
37 ms |
67708 KB |
Output is correct |
25 |
Correct |
46 ms |
67704 KB |
Output is correct |
26 |
Correct |
30 ms |
67624 KB |
Output is correct |
27 |
Correct |
47 ms |
67704 KB |
Output is correct |
28 |
Correct |
39 ms |
67780 KB |
Output is correct |
29 |
Correct |
46 ms |
67708 KB |
Output is correct |
30 |
Correct |
37 ms |
67708 KB |
Output is correct |
31 |
Correct |
45 ms |
67656 KB |
Output is correct |
32 |
Correct |
31 ms |
67660 KB |
Output is correct |
33 |
Correct |
44 ms |
67660 KB |
Output is correct |
34 |
Correct |
36 ms |
67656 KB |
Output is correct |
35 |
Correct |
41 ms |
67660 KB |
Output is correct |
36 |
Correct |
30 ms |
67696 KB |
Output is correct |
37 |
Correct |
39 ms |
67676 KB |
Output is correct |
38 |
Correct |
32 ms |
67728 KB |
Output is correct |
39 |
Correct |
46 ms |
67732 KB |
Output is correct |
40 |
Correct |
33 ms |
67660 KB |
Output is correct |
41 |
Correct |
232 ms |
67708 KB |
Output is correct |
42 |
Correct |
89 ms |
67720 KB |
Output is correct |
43 |
Correct |
220 ms |
67652 KB |
Output is correct |
44 |
Correct |
96 ms |
67748 KB |
Output is correct |
45 |
Correct |
221 ms |
67652 KB |
Output is correct |
46 |
Correct |
90 ms |
67704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
67660 KB |
Output is correct |
2 |
Correct |
27 ms |
67616 KB |
Output is correct |
3 |
Correct |
26 ms |
67660 KB |
Output is correct |
4 |
Correct |
25 ms |
67612 KB |
Output is correct |
5 |
Correct |
25 ms |
67688 KB |
Output is correct |
6 |
Correct |
24 ms |
67676 KB |
Output is correct |
7 |
Correct |
25 ms |
67652 KB |
Output is correct |
8 |
Correct |
24 ms |
67676 KB |
Output is correct |
9 |
Correct |
24 ms |
67648 KB |
Output is correct |
10 |
Correct |
25 ms |
67720 KB |
Output is correct |
11 |
Correct |
25 ms |
67644 KB |
Output is correct |
12 |
Correct |
26 ms |
67688 KB |
Output is correct |
13 |
Correct |
24 ms |
67732 KB |
Output is correct |
14 |
Correct |
24 ms |
67660 KB |
Output is correct |
15 |
Correct |
24 ms |
67660 KB |
Output is correct |
16 |
Correct |
24 ms |
67684 KB |
Output is correct |
17 |
Correct |
28 ms |
67644 KB |
Output is correct |
18 |
Correct |
24 ms |
67660 KB |
Output is correct |
19 |
Correct |
23 ms |
67652 KB |
Output is correct |
20 |
Correct |
25 ms |
67616 KB |
Output is correct |
21 |
Correct |
25 ms |
67624 KB |
Output is correct |
22 |
Correct |
26 ms |
67596 KB |
Output is correct |
23 |
Correct |
28 ms |
67652 KB |
Output is correct |
24 |
Correct |
24 ms |
67660 KB |
Output is correct |
25 |
Correct |
25 ms |
67632 KB |
Output is correct |
26 |
Correct |
24 ms |
67660 KB |
Output is correct |
27 |
Correct |
26 ms |
67684 KB |
Output is correct |
28 |
Correct |
25 ms |
67684 KB |
Output is correct |
29 |
Correct |
24 ms |
67728 KB |
Output is correct |
30 |
Correct |
27 ms |
67612 KB |
Output is correct |
31 |
Correct |
25 ms |
67660 KB |
Output is correct |
32 |
Correct |
25 ms |
67628 KB |
Output is correct |
33 |
Correct |
25 ms |
67732 KB |
Output is correct |
34 |
Correct |
24 ms |
67660 KB |
Output is correct |
35 |
Correct |
25 ms |
67724 KB |
Output is correct |
36 |
Correct |
151 ms |
67660 KB |
Output is correct |
37 |
Correct |
89 ms |
67704 KB |
Output is correct |
38 |
Correct |
52 ms |
67660 KB |
Output is correct |
39 |
Correct |
89 ms |
67776 KB |
Output is correct |
40 |
Correct |
110 ms |
67708 KB |
Output is correct |
41 |
Correct |
48 ms |
67660 KB |
Output is correct |
42 |
Correct |
37 ms |
67708 KB |
Output is correct |
43 |
Correct |
46 ms |
67704 KB |
Output is correct |
44 |
Correct |
30 ms |
67624 KB |
Output is correct |
45 |
Correct |
47 ms |
67704 KB |
Output is correct |
46 |
Correct |
39 ms |
67780 KB |
Output is correct |
47 |
Correct |
46 ms |
67708 KB |
Output is correct |
48 |
Correct |
37 ms |
67708 KB |
Output is correct |
49 |
Correct |
45 ms |
67656 KB |
Output is correct |
50 |
Correct |
31 ms |
67660 KB |
Output is correct |
51 |
Correct |
44 ms |
67660 KB |
Output is correct |
52 |
Correct |
36 ms |
67656 KB |
Output is correct |
53 |
Correct |
41 ms |
67660 KB |
Output is correct |
54 |
Correct |
30 ms |
67696 KB |
Output is correct |
55 |
Correct |
39 ms |
67676 KB |
Output is correct |
56 |
Correct |
32 ms |
67728 KB |
Output is correct |
57 |
Correct |
46 ms |
67732 KB |
Output is correct |
58 |
Correct |
33 ms |
67660 KB |
Output is correct |
59 |
Correct |
232 ms |
67708 KB |
Output is correct |
60 |
Correct |
89 ms |
67720 KB |
Output is correct |
61 |
Correct |
220 ms |
67652 KB |
Output is correct |
62 |
Correct |
96 ms |
67748 KB |
Output is correct |
63 |
Correct |
221 ms |
67652 KB |
Output is correct |
64 |
Correct |
90 ms |
67704 KB |
Output is correct |
65 |
Correct |
135 ms |
67704 KB |
Output is correct |
66 |
Correct |
133 ms |
67712 KB |
Output is correct |
67 |
Correct |
115 ms |
67676 KB |
Output is correct |
68 |
Correct |
105 ms |
67660 KB |
Output is correct |
69 |
Correct |
137 ms |
67616 KB |
Output is correct |
70 |
Correct |
130 ms |
67640 KB |
Output is correct |
71 |
Correct |
137 ms |
67708 KB |
Output is correct |
72 |
Correct |
131 ms |
67620 KB |
Output is correct |
73 |
Correct |
138 ms |
67660 KB |
Output is correct |
74 |
Correct |
113 ms |
67712 KB |
Output is correct |
75 |
Correct |
133 ms |
67784 KB |
Output is correct |
76 |
Correct |
199 ms |
67612 KB |
Output is correct |
77 |
Correct |
146 ms |
67712 KB |
Output is correct |
78 |
Correct |
145 ms |
67716 KB |
Output is correct |
79 |
Correct |
120 ms |
67716 KB |
Output is correct |
80 |
Correct |
195 ms |
67696 KB |
Output is correct |
81 |
Correct |
116 ms |
67664 KB |
Output is correct |
82 |
Correct |
140 ms |
67712 KB |
Output is correct |
83 |
Correct |
160 ms |
67784 KB |
Output is correct |
84 |
Correct |
149 ms |
67716 KB |
Output is correct |
85 |
Correct |
187 ms |
67716 KB |
Output is correct |
86 |
Correct |
161 ms |
67664 KB |
Output is correct |
87 |
Correct |
129 ms |
67768 KB |
Output is correct |
88 |
Correct |
164 ms |
67716 KB |
Output is correct |
89 |
Correct |
149 ms |
67664 KB |
Output is correct |
90 |
Correct |
121 ms |
67716 KB |
Output is correct |
91 |
Correct |
171 ms |
67720 KB |
Output is correct |
92 |
Correct |
147 ms |
67712 KB |
Output is correct |
93 |
Correct |
137 ms |
67664 KB |
Output is correct |