//自己想到的,好開心(對照過提解了,確定是對的)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, l, a[210], t[210];
ll inf = 1e13;
ll dp[210][210][210][2]; //dp[l][r][k][w]代表逆時針走過l,順時針走過r,共拿過k個郵票,現在在哪個端點(w=0是左),所需的最短時間
int walk (int st, int ed) {
if (st == ed) return 0;
if (st > ed) swap(st, ed);
return min((a[st] + l - a[ed]), a[ed] - a[st]);
}
signed main () {
ios_base::sync_with_stdio(false); cin.tie(0);
memset(dp, 63, sizeof(dp));
dp[0][0][0][0] = dp[0][0][0][1] = 0;
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> t[i];
a[0] = 0, a[n + 1] = l, t[0] = t[n + 1] = -1;
int ans = 0;
for (int l = 0; l <= n; l++) {
for (int r = 0; r <= n and l + r <= n; r++) {
for (int k = 0; k <= n; k++) {
if (min(dp[l][r][k][1], dp[l][r][k][0]) < inf) {
// if (k > ans) cout << l << ' ' << r << ' ' << k << ' ' << dp[l][r][k][0] << ' ' << dp[l][r][k][1] << '\n';
ans = max(ans, k);
}
//逆時針
if (l + 1 <= n){
ll tt = dp[l][r][k][0] + walk(n + 1 - l, n + 1 - (l + 1));
tt = min(tt, dp[l][r][k][1] + walk(r, n + 1 - (l + 1)) );
if (tt <= t[n + 1 - (l + 1)]) dp[l + 1][r][k + 1][0] = min(dp[l + 1][r][k + 1][0], tt);
else dp[l + 1][r][k][0] = min(dp[l + 1][r][k][0], tt);
}
//順時針
if (r + 1 <= n){
ll tt = dp[l][r][k][0] + walk(n + 1 - l, r + 1);
tt = min(tt, dp[l][r][k][1] + walk(r, r + 1) );
if (tt <= t[r + 1]) dp[l][r + 1][k + 1][1] = min(dp[l][r + 1][k + 1][1], tt);
else dp[l][r + 1][k][1] = min(dp[l][r + 1][k][1], tt);
}
}
}
}
cout << ans << '\n';
return 0;}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
145492 KB |
Output is correct |
2 |
Correct |
29 ms |
145236 KB |
Output is correct |
3 |
Correct |
32 ms |
145340 KB |
Output is correct |
4 |
Correct |
29 ms |
145312 KB |
Output is correct |
5 |
Correct |
29 ms |
145328 KB |
Output is correct |
6 |
Correct |
29 ms |
145244 KB |
Output is correct |
7 |
Correct |
29 ms |
145236 KB |
Output is correct |
8 |
Correct |
29 ms |
145236 KB |
Output is correct |
9 |
Correct |
29 ms |
145232 KB |
Output is correct |
10 |
Correct |
28 ms |
145236 KB |
Output is correct |
11 |
Correct |
30 ms |
145492 KB |
Output is correct |
12 |
Correct |
29 ms |
145216 KB |
Output is correct |
13 |
Correct |
28 ms |
145244 KB |
Output is correct |
14 |
Correct |
30 ms |
145244 KB |
Output is correct |
15 |
Correct |
29 ms |
145244 KB |
Output is correct |
16 |
Correct |
28 ms |
145232 KB |
Output is correct |
17 |
Correct |
30 ms |
145340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
145492 KB |
Output is correct |
2 |
Correct |
29 ms |
145236 KB |
Output is correct |
3 |
Correct |
32 ms |
145340 KB |
Output is correct |
4 |
Correct |
29 ms |
145312 KB |
Output is correct |
5 |
Correct |
29 ms |
145328 KB |
Output is correct |
6 |
Correct |
29 ms |
145244 KB |
Output is correct |
7 |
Correct |
29 ms |
145236 KB |
Output is correct |
8 |
Correct |
29 ms |
145236 KB |
Output is correct |
9 |
Correct |
29 ms |
145232 KB |
Output is correct |
10 |
Correct |
28 ms |
145236 KB |
Output is correct |
11 |
Correct |
30 ms |
145492 KB |
Output is correct |
12 |
Correct |
29 ms |
145216 KB |
Output is correct |
13 |
Correct |
28 ms |
145244 KB |
Output is correct |
14 |
Correct |
30 ms |
145244 KB |
Output is correct |
15 |
Correct |
29 ms |
145244 KB |
Output is correct |
16 |
Correct |
28 ms |
145232 KB |
Output is correct |
17 |
Correct |
30 ms |
145340 KB |
Output is correct |
18 |
Correct |
30 ms |
145232 KB |
Output is correct |
19 |
Correct |
28 ms |
145240 KB |
Output is correct |
20 |
Correct |
30 ms |
145496 KB |
Output is correct |
21 |
Correct |
29 ms |
145408 KB |
Output is correct |
22 |
Correct |
29 ms |
145236 KB |
Output is correct |
23 |
Correct |
29 ms |
145240 KB |
Output is correct |
24 |
Correct |
29 ms |
145232 KB |
Output is correct |
25 |
Correct |
28 ms |
145244 KB |
Output is correct |
26 |
Correct |
30 ms |
145228 KB |
Output is correct |
27 |
Correct |
28 ms |
145244 KB |
Output is correct |
28 |
Correct |
29 ms |
145236 KB |
Output is correct |
29 |
Correct |
29 ms |
145240 KB |
Output is correct |
30 |
Correct |
29 ms |
145244 KB |
Output is correct |
31 |
Correct |
30 ms |
145244 KB |
Output is correct |
32 |
Correct |
30 ms |
145244 KB |
Output is correct |
33 |
Correct |
29 ms |
145232 KB |
Output is correct |
34 |
Correct |
28 ms |
145232 KB |
Output is correct |
35 |
Correct |
28 ms |
145240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
145492 KB |
Output is correct |
2 |
Correct |
29 ms |
145236 KB |
Output is correct |
3 |
Correct |
32 ms |
145340 KB |
Output is correct |
4 |
Correct |
29 ms |
145312 KB |
Output is correct |
5 |
Correct |
29 ms |
145328 KB |
Output is correct |
6 |
Correct |
29 ms |
145244 KB |
Output is correct |
7 |
Correct |
29 ms |
145236 KB |
Output is correct |
8 |
Correct |
29 ms |
145236 KB |
Output is correct |
9 |
Correct |
29 ms |
145232 KB |
Output is correct |
10 |
Correct |
28 ms |
145236 KB |
Output is correct |
11 |
Correct |
30 ms |
145492 KB |
Output is correct |
12 |
Correct |
29 ms |
145216 KB |
Output is correct |
13 |
Correct |
28 ms |
145244 KB |
Output is correct |
14 |
Correct |
30 ms |
145244 KB |
Output is correct |
15 |
Correct |
29 ms |
145244 KB |
Output is correct |
16 |
Correct |
28 ms |
145232 KB |
Output is correct |
17 |
Correct |
30 ms |
145340 KB |
Output is correct |
18 |
Correct |
55 ms |
145232 KB |
Output is correct |
19 |
Correct |
45 ms |
145284 KB |
Output is correct |
20 |
Correct |
36 ms |
145236 KB |
Output is correct |
21 |
Correct |
45 ms |
145244 KB |
Output is correct |
22 |
Correct |
49 ms |
145236 KB |
Output is correct |
23 |
Correct |
37 ms |
145496 KB |
Output is correct |
24 |
Correct |
35 ms |
145232 KB |
Output is correct |
25 |
Correct |
34 ms |
145200 KB |
Output is correct |
26 |
Correct |
32 ms |
145288 KB |
Output is correct |
27 |
Correct |
36 ms |
145244 KB |
Output is correct |
28 |
Correct |
32 ms |
145244 KB |
Output is correct |
29 |
Correct |
34 ms |
145232 KB |
Output is correct |
30 |
Correct |
33 ms |
145240 KB |
Output is correct |
31 |
Correct |
37 ms |
145236 KB |
Output is correct |
32 |
Correct |
31 ms |
145416 KB |
Output is correct |
33 |
Correct |
35 ms |
145244 KB |
Output is correct |
34 |
Correct |
30 ms |
145232 KB |
Output is correct |
35 |
Correct |
34 ms |
145236 KB |
Output is correct |
36 |
Correct |
30 ms |
145236 KB |
Output is correct |
37 |
Correct |
34 ms |
145488 KB |
Output is correct |
38 |
Correct |
32 ms |
145236 KB |
Output is correct |
39 |
Correct |
36 ms |
145236 KB |
Output is correct |
40 |
Correct |
33 ms |
145400 KB |
Output is correct |
41 |
Correct |
62 ms |
145236 KB |
Output is correct |
42 |
Correct |
52 ms |
145236 KB |
Output is correct |
43 |
Correct |
65 ms |
145244 KB |
Output is correct |
44 |
Correct |
50 ms |
145240 KB |
Output is correct |
45 |
Correct |
64 ms |
145236 KB |
Output is correct |
46 |
Correct |
49 ms |
145416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
145492 KB |
Output is correct |
2 |
Correct |
29 ms |
145236 KB |
Output is correct |
3 |
Correct |
32 ms |
145340 KB |
Output is correct |
4 |
Correct |
29 ms |
145312 KB |
Output is correct |
5 |
Correct |
29 ms |
145328 KB |
Output is correct |
6 |
Correct |
29 ms |
145244 KB |
Output is correct |
7 |
Correct |
29 ms |
145236 KB |
Output is correct |
8 |
Correct |
29 ms |
145236 KB |
Output is correct |
9 |
Correct |
29 ms |
145232 KB |
Output is correct |
10 |
Correct |
28 ms |
145236 KB |
Output is correct |
11 |
Correct |
30 ms |
145492 KB |
Output is correct |
12 |
Correct |
29 ms |
145216 KB |
Output is correct |
13 |
Correct |
28 ms |
145244 KB |
Output is correct |
14 |
Correct |
30 ms |
145244 KB |
Output is correct |
15 |
Correct |
29 ms |
145244 KB |
Output is correct |
16 |
Correct |
28 ms |
145232 KB |
Output is correct |
17 |
Correct |
30 ms |
145340 KB |
Output is correct |
18 |
Correct |
30 ms |
145232 KB |
Output is correct |
19 |
Correct |
28 ms |
145240 KB |
Output is correct |
20 |
Correct |
30 ms |
145496 KB |
Output is correct |
21 |
Correct |
29 ms |
145408 KB |
Output is correct |
22 |
Correct |
29 ms |
145236 KB |
Output is correct |
23 |
Correct |
29 ms |
145240 KB |
Output is correct |
24 |
Correct |
29 ms |
145232 KB |
Output is correct |
25 |
Correct |
28 ms |
145244 KB |
Output is correct |
26 |
Correct |
30 ms |
145228 KB |
Output is correct |
27 |
Correct |
28 ms |
145244 KB |
Output is correct |
28 |
Correct |
29 ms |
145236 KB |
Output is correct |
29 |
Correct |
29 ms |
145240 KB |
Output is correct |
30 |
Correct |
29 ms |
145244 KB |
Output is correct |
31 |
Correct |
30 ms |
145244 KB |
Output is correct |
32 |
Correct |
30 ms |
145244 KB |
Output is correct |
33 |
Correct |
29 ms |
145232 KB |
Output is correct |
34 |
Correct |
28 ms |
145232 KB |
Output is correct |
35 |
Correct |
28 ms |
145240 KB |
Output is correct |
36 |
Correct |
55 ms |
145232 KB |
Output is correct |
37 |
Correct |
45 ms |
145284 KB |
Output is correct |
38 |
Correct |
36 ms |
145236 KB |
Output is correct |
39 |
Correct |
45 ms |
145244 KB |
Output is correct |
40 |
Correct |
49 ms |
145236 KB |
Output is correct |
41 |
Correct |
37 ms |
145496 KB |
Output is correct |
42 |
Correct |
35 ms |
145232 KB |
Output is correct |
43 |
Correct |
34 ms |
145200 KB |
Output is correct |
44 |
Correct |
32 ms |
145288 KB |
Output is correct |
45 |
Correct |
36 ms |
145244 KB |
Output is correct |
46 |
Correct |
32 ms |
145244 KB |
Output is correct |
47 |
Correct |
34 ms |
145232 KB |
Output is correct |
48 |
Correct |
33 ms |
145240 KB |
Output is correct |
49 |
Correct |
37 ms |
145236 KB |
Output is correct |
50 |
Correct |
31 ms |
145416 KB |
Output is correct |
51 |
Correct |
35 ms |
145244 KB |
Output is correct |
52 |
Correct |
30 ms |
145232 KB |
Output is correct |
53 |
Correct |
34 ms |
145236 KB |
Output is correct |
54 |
Correct |
30 ms |
145236 KB |
Output is correct |
55 |
Correct |
34 ms |
145488 KB |
Output is correct |
56 |
Correct |
32 ms |
145236 KB |
Output is correct |
57 |
Correct |
36 ms |
145236 KB |
Output is correct |
58 |
Correct |
33 ms |
145400 KB |
Output is correct |
59 |
Correct |
62 ms |
145236 KB |
Output is correct |
60 |
Correct |
52 ms |
145236 KB |
Output is correct |
61 |
Correct |
65 ms |
145244 KB |
Output is correct |
62 |
Correct |
50 ms |
145240 KB |
Output is correct |
63 |
Correct |
64 ms |
145236 KB |
Output is correct |
64 |
Correct |
49 ms |
145416 KB |
Output is correct |
65 |
Correct |
59 ms |
145420 KB |
Output is correct |
66 |
Correct |
58 ms |
145424 KB |
Output is correct |
67 |
Correct |
53 ms |
145236 KB |
Output is correct |
68 |
Correct |
53 ms |
145336 KB |
Output is correct |
69 |
Correct |
61 ms |
145236 KB |
Output is correct |
70 |
Correct |
57 ms |
145424 KB |
Output is correct |
71 |
Correct |
60 ms |
145236 KB |
Output is correct |
72 |
Correct |
57 ms |
145232 KB |
Output is correct |
73 |
Correct |
58 ms |
145556 KB |
Output is correct |
74 |
Correct |
52 ms |
145396 KB |
Output is correct |
75 |
Correct |
59 ms |
145428 KB |
Output is correct |
76 |
Correct |
61 ms |
145232 KB |
Output is correct |
77 |
Correct |
64 ms |
145232 KB |
Output is correct |
78 |
Correct |
60 ms |
145312 KB |
Output is correct |
79 |
Correct |
55 ms |
145244 KB |
Output is correct |
80 |
Correct |
62 ms |
145420 KB |
Output is correct |
81 |
Correct |
56 ms |
145240 KB |
Output is correct |
82 |
Correct |
58 ms |
145356 KB |
Output is correct |
83 |
Correct |
65 ms |
145416 KB |
Output is correct |
84 |
Correct |
59 ms |
145236 KB |
Output is correct |
85 |
Correct |
59 ms |
145244 KB |
Output is correct |
86 |
Correct |
60 ms |
145232 KB |
Output is correct |
87 |
Correct |
58 ms |
145424 KB |
Output is correct |
88 |
Correct |
64 ms |
145232 KB |
Output is correct |
89 |
Correct |
64 ms |
145432 KB |
Output is correct |
90 |
Correct |
59 ms |
145244 KB |
Output is correct |
91 |
Correct |
68 ms |
145424 KB |
Output is correct |
92 |
Correct |
65 ms |
145428 KB |
Output is correct |
93 |
Correct |
66 ms |
145240 KB |
Output is correct |