#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) continue;
if (sz == n){ ans = x; 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
67660 KB |
Output is correct |
2 |
Correct |
25 ms |
67604 KB |
Output is correct |
3 |
Correct |
25 ms |
67664 KB |
Output is correct |
4 |
Correct |
25 ms |
67712 KB |
Output is correct |
5 |
Correct |
26 ms |
67656 KB |
Output is correct |
6 |
Correct |
25 ms |
67640 KB |
Output is correct |
7 |
Correct |
26 ms |
67676 KB |
Output is correct |
8 |
Correct |
26 ms |
67640 KB |
Output is correct |
9 |
Correct |
25 ms |
67696 KB |
Output is correct |
10 |
Correct |
25 ms |
67716 KB |
Output is correct |
11 |
Correct |
24 ms |
67704 KB |
Output is correct |
12 |
Correct |
24 ms |
67628 KB |
Output is correct |
13 |
Correct |
25 ms |
67700 KB |
Output is correct |
14 |
Correct |
25 ms |
67688 KB |
Output is correct |
15 |
Correct |
25 ms |
67660 KB |
Output is correct |
16 |
Correct |
26 ms |
67732 KB |
Output is correct |
17 |
Correct |
24 ms |
67608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
67660 KB |
Output is correct |
2 |
Correct |
25 ms |
67604 KB |
Output is correct |
3 |
Correct |
25 ms |
67664 KB |
Output is correct |
4 |
Correct |
25 ms |
67712 KB |
Output is correct |
5 |
Correct |
26 ms |
67656 KB |
Output is correct |
6 |
Correct |
25 ms |
67640 KB |
Output is correct |
7 |
Correct |
26 ms |
67676 KB |
Output is correct |
8 |
Correct |
26 ms |
67640 KB |
Output is correct |
9 |
Correct |
25 ms |
67696 KB |
Output is correct |
10 |
Correct |
25 ms |
67716 KB |
Output is correct |
11 |
Correct |
24 ms |
67704 KB |
Output is correct |
12 |
Correct |
24 ms |
67628 KB |
Output is correct |
13 |
Correct |
25 ms |
67700 KB |
Output is correct |
14 |
Correct |
25 ms |
67688 KB |
Output is correct |
15 |
Correct |
25 ms |
67660 KB |
Output is correct |
16 |
Correct |
26 ms |
67732 KB |
Output is correct |
17 |
Correct |
24 ms |
67608 KB |
Output is correct |
18 |
Correct |
25 ms |
67676 KB |
Output is correct |
19 |
Correct |
25 ms |
67608 KB |
Output is correct |
20 |
Correct |
25 ms |
67696 KB |
Output is correct |
21 |
Correct |
25 ms |
67660 KB |
Output is correct |
22 |
Correct |
25 ms |
67664 KB |
Output is correct |
23 |
Correct |
29 ms |
67664 KB |
Output is correct |
24 |
Correct |
25 ms |
67660 KB |
Output is correct |
25 |
Correct |
27 ms |
67708 KB |
Output is correct |
26 |
Correct |
26 ms |
67660 KB |
Output is correct |
27 |
Correct |
25 ms |
67688 KB |
Output is correct |
28 |
Correct |
26 ms |
67636 KB |
Output is correct |
29 |
Correct |
29 ms |
67652 KB |
Output is correct |
30 |
Correct |
25 ms |
67716 KB |
Output is correct |
31 |
Correct |
27 ms |
67660 KB |
Output is correct |
32 |
Correct |
25 ms |
67660 KB |
Output is correct |
33 |
Correct |
25 ms |
67664 KB |
Output is correct |
34 |
Correct |
25 ms |
67660 KB |
Output is correct |
35 |
Correct |
25 ms |
67660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
67660 KB |
Output is correct |
2 |
Correct |
25 ms |
67604 KB |
Output is correct |
3 |
Correct |
25 ms |
67664 KB |
Output is correct |
4 |
Correct |
25 ms |
67712 KB |
Output is correct |
5 |
Correct |
26 ms |
67656 KB |
Output is correct |
6 |
Correct |
25 ms |
67640 KB |
Output is correct |
7 |
Correct |
26 ms |
67676 KB |
Output is correct |
8 |
Correct |
26 ms |
67640 KB |
Output is correct |
9 |
Correct |
25 ms |
67696 KB |
Output is correct |
10 |
Correct |
25 ms |
67716 KB |
Output is correct |
11 |
Correct |
24 ms |
67704 KB |
Output is correct |
12 |
Correct |
24 ms |
67628 KB |
Output is correct |
13 |
Correct |
25 ms |
67700 KB |
Output is correct |
14 |
Correct |
25 ms |
67688 KB |
Output is correct |
15 |
Correct |
25 ms |
67660 KB |
Output is correct |
16 |
Correct |
26 ms |
67732 KB |
Output is correct |
17 |
Correct |
24 ms |
67608 KB |
Output is correct |
18 |
Correct |
153 ms |
67720 KB |
Output is correct |
19 |
Correct |
95 ms |
67716 KB |
Output is correct |
20 |
Correct |
49 ms |
67712 KB |
Output is correct |
21 |
Correct |
85 ms |
67716 KB |
Output is correct |
22 |
Correct |
111 ms |
67712 KB |
Output is correct |
23 |
Correct |
47 ms |
67652 KB |
Output is correct |
24 |
Correct |
36 ms |
67656 KB |
Output is correct |
25 |
Correct |
47 ms |
67660 KB |
Output is correct |
26 |
Correct |
29 ms |
67728 KB |
Output is correct |
27 |
Correct |
46 ms |
67708 KB |
Output is correct |
28 |
Correct |
39 ms |
67624 KB |
Output is correct |
29 |
Correct |
53 ms |
67736 KB |
Output is correct |
30 |
Correct |
39 ms |
67724 KB |
Output is correct |
31 |
Correct |
43 ms |
67712 KB |
Output is correct |
32 |
Correct |
31 ms |
67632 KB |
Output is correct |
33 |
Correct |
43 ms |
67720 KB |
Output is correct |
34 |
Correct |
29 ms |
67668 KB |
Output is correct |
35 |
Correct |
38 ms |
67680 KB |
Output is correct |
36 |
Correct |
33 ms |
67736 KB |
Output is correct |
37 |
Correct |
40 ms |
67668 KB |
Output is correct |
38 |
Correct |
34 ms |
67724 KB |
Output is correct |
39 |
Correct |
44 ms |
67656 KB |
Output is correct |
40 |
Correct |
33 ms |
67668 KB |
Output is correct |
41 |
Correct |
221 ms |
67596 KB |
Output is correct |
42 |
Correct |
90 ms |
67664 KB |
Output is correct |
43 |
Correct |
224 ms |
67716 KB |
Output is correct |
44 |
Correct |
89 ms |
67696 KB |
Output is correct |
45 |
Correct |
223 ms |
67716 KB |
Output is correct |
46 |
Correct |
94 ms |
67720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
67660 KB |
Output is correct |
2 |
Correct |
25 ms |
67604 KB |
Output is correct |
3 |
Correct |
25 ms |
67664 KB |
Output is correct |
4 |
Correct |
25 ms |
67712 KB |
Output is correct |
5 |
Correct |
26 ms |
67656 KB |
Output is correct |
6 |
Correct |
25 ms |
67640 KB |
Output is correct |
7 |
Correct |
26 ms |
67676 KB |
Output is correct |
8 |
Correct |
26 ms |
67640 KB |
Output is correct |
9 |
Correct |
25 ms |
67696 KB |
Output is correct |
10 |
Correct |
25 ms |
67716 KB |
Output is correct |
11 |
Correct |
24 ms |
67704 KB |
Output is correct |
12 |
Correct |
24 ms |
67628 KB |
Output is correct |
13 |
Correct |
25 ms |
67700 KB |
Output is correct |
14 |
Correct |
25 ms |
67688 KB |
Output is correct |
15 |
Correct |
25 ms |
67660 KB |
Output is correct |
16 |
Correct |
26 ms |
67732 KB |
Output is correct |
17 |
Correct |
24 ms |
67608 KB |
Output is correct |
18 |
Correct |
25 ms |
67676 KB |
Output is correct |
19 |
Correct |
25 ms |
67608 KB |
Output is correct |
20 |
Correct |
25 ms |
67696 KB |
Output is correct |
21 |
Correct |
25 ms |
67660 KB |
Output is correct |
22 |
Correct |
25 ms |
67664 KB |
Output is correct |
23 |
Correct |
29 ms |
67664 KB |
Output is correct |
24 |
Correct |
25 ms |
67660 KB |
Output is correct |
25 |
Correct |
27 ms |
67708 KB |
Output is correct |
26 |
Correct |
26 ms |
67660 KB |
Output is correct |
27 |
Correct |
25 ms |
67688 KB |
Output is correct |
28 |
Correct |
26 ms |
67636 KB |
Output is correct |
29 |
Correct |
29 ms |
67652 KB |
Output is correct |
30 |
Correct |
25 ms |
67716 KB |
Output is correct |
31 |
Correct |
27 ms |
67660 KB |
Output is correct |
32 |
Correct |
25 ms |
67660 KB |
Output is correct |
33 |
Correct |
25 ms |
67664 KB |
Output is correct |
34 |
Correct |
25 ms |
67660 KB |
Output is correct |
35 |
Correct |
25 ms |
67660 KB |
Output is correct |
36 |
Correct |
153 ms |
67720 KB |
Output is correct |
37 |
Correct |
95 ms |
67716 KB |
Output is correct |
38 |
Correct |
49 ms |
67712 KB |
Output is correct |
39 |
Correct |
85 ms |
67716 KB |
Output is correct |
40 |
Correct |
111 ms |
67712 KB |
Output is correct |
41 |
Correct |
47 ms |
67652 KB |
Output is correct |
42 |
Correct |
36 ms |
67656 KB |
Output is correct |
43 |
Correct |
47 ms |
67660 KB |
Output is correct |
44 |
Correct |
29 ms |
67728 KB |
Output is correct |
45 |
Correct |
46 ms |
67708 KB |
Output is correct |
46 |
Correct |
39 ms |
67624 KB |
Output is correct |
47 |
Correct |
53 ms |
67736 KB |
Output is correct |
48 |
Correct |
39 ms |
67724 KB |
Output is correct |
49 |
Correct |
43 ms |
67712 KB |
Output is correct |
50 |
Correct |
31 ms |
67632 KB |
Output is correct |
51 |
Correct |
43 ms |
67720 KB |
Output is correct |
52 |
Correct |
29 ms |
67668 KB |
Output is correct |
53 |
Correct |
38 ms |
67680 KB |
Output is correct |
54 |
Correct |
33 ms |
67736 KB |
Output is correct |
55 |
Correct |
40 ms |
67668 KB |
Output is correct |
56 |
Correct |
34 ms |
67724 KB |
Output is correct |
57 |
Correct |
44 ms |
67656 KB |
Output is correct |
58 |
Correct |
33 ms |
67668 KB |
Output is correct |
59 |
Correct |
221 ms |
67596 KB |
Output is correct |
60 |
Correct |
90 ms |
67664 KB |
Output is correct |
61 |
Correct |
224 ms |
67716 KB |
Output is correct |
62 |
Correct |
89 ms |
67696 KB |
Output is correct |
63 |
Correct |
223 ms |
67716 KB |
Output is correct |
64 |
Correct |
94 ms |
67720 KB |
Output is correct |
65 |
Correct |
135 ms |
67628 KB |
Output is correct |
66 |
Correct |
126 ms |
67708 KB |
Output is correct |
67 |
Correct |
116 ms |
67716 KB |
Output is correct |
68 |
Correct |
106 ms |
67716 KB |
Output is correct |
69 |
Correct |
137 ms |
67720 KB |
Output is correct |
70 |
Correct |
134 ms |
67784 KB |
Output is correct |
71 |
Correct |
139 ms |
67692 KB |
Output is correct |
72 |
Correct |
134 ms |
67712 KB |
Output is correct |
73 |
Correct |
139 ms |
67712 KB |
Output is correct |
74 |
Correct |
114 ms |
67712 KB |
Output is correct |
75 |
Incorrect |
128 ms |
67716 KB |
Output isn't correct |
76 |
Halted |
0 ms |
0 KB |
- |