#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define MX(a,b) a=max(a,b)
#define MN(a,b) a=min(a,b)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT
void GG(){cout<<-1<<endl; exit(0);}
const int maxn = 204;
ll n,L;
ll X[maxn], T[maxn];
ll dp[maxn][maxn][2][maxn]; // (l,r) is not explored, ,stamps)
signed main(){
IOS();
memset(dp, 0x3f, sizeof dp);
cin>>n>>L;
for (ll i = 1 ;i<=n; ++i) cin>>X[i];
X[n+1] = L;
for (ll i = 1 ;i<=n; ++i) cin>>T[i];
++n;
dp[0][n][0][0]=0;
dp[0][n][1][0]=0;
T[0] = -1;
ll re = 0;
for (ll df = n-1; df >= 1; --df) {
for (ll i = 0; i+df <= n; ++i) {
ll j = i+df;
for (ll g = 0; g <= n; ++g) {
if (i)
MN(dp[i][j][0][g], dp[i-1][j][0][g] + X[i] - X[i-1]);
if (j!=n)
MN(dp[i][j][1][g], dp[i][j+1][1][g] + X[j+1] - X[j]);
if (g) {
if (i && dp[i-1][j][0][g-1] + X[i] - X[i-1] <= T[i])
MN(dp[i][j][0][g], dp[i-1][j][0][g-1] + X[i] - X[i-1]);
if (j != n && dp[i][j+1][1][g-1] + X[j+1] - X[j] <= T[j])
MN(dp[i][j][1][g], dp[i][j+1][1][g-1] + X[j+1] - X[j]);
}
MN(dp[i][j][0][g], dp[i][j][1][g] + L - X[j] + X[i]);
MN(dp[i][j][1][g], dp[i][j][0][g] + L - X[j] + X[i]);
if (min(dp[i][j][0][g],dp[i][j][1][g]) < 10000000000ll) {
MX(re, g);
bug(dp[i][j][0][g], i,j,g);
}
}
}
}
cout<<re<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
133240 KB |
Output is correct |
2 |
Correct |
71 ms |
133244 KB |
Output is correct |
3 |
Correct |
70 ms |
133368 KB |
Output is correct |
4 |
Correct |
72 ms |
133240 KB |
Output is correct |
5 |
Correct |
70 ms |
133240 KB |
Output is correct |
6 |
Correct |
71 ms |
133240 KB |
Output is correct |
7 |
Correct |
74 ms |
133240 KB |
Output is correct |
8 |
Correct |
73 ms |
133240 KB |
Output is correct |
9 |
Correct |
73 ms |
133240 KB |
Output is correct |
10 |
Correct |
74 ms |
133244 KB |
Output is correct |
11 |
Correct |
73 ms |
133240 KB |
Output is correct |
12 |
Correct |
72 ms |
133240 KB |
Output is correct |
13 |
Correct |
73 ms |
133272 KB |
Output is correct |
14 |
Correct |
72 ms |
133240 KB |
Output is correct |
15 |
Correct |
72 ms |
133240 KB |
Output is correct |
16 |
Correct |
72 ms |
133240 KB |
Output is correct |
17 |
Correct |
72 ms |
133248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
133240 KB |
Output is correct |
2 |
Correct |
71 ms |
133244 KB |
Output is correct |
3 |
Correct |
70 ms |
133368 KB |
Output is correct |
4 |
Correct |
72 ms |
133240 KB |
Output is correct |
5 |
Correct |
70 ms |
133240 KB |
Output is correct |
6 |
Correct |
71 ms |
133240 KB |
Output is correct |
7 |
Correct |
74 ms |
133240 KB |
Output is correct |
8 |
Correct |
73 ms |
133240 KB |
Output is correct |
9 |
Correct |
73 ms |
133240 KB |
Output is correct |
10 |
Correct |
74 ms |
133244 KB |
Output is correct |
11 |
Correct |
73 ms |
133240 KB |
Output is correct |
12 |
Correct |
72 ms |
133240 KB |
Output is correct |
13 |
Correct |
73 ms |
133272 KB |
Output is correct |
14 |
Correct |
72 ms |
133240 KB |
Output is correct |
15 |
Correct |
72 ms |
133240 KB |
Output is correct |
16 |
Correct |
72 ms |
133240 KB |
Output is correct |
17 |
Correct |
72 ms |
133248 KB |
Output is correct |
18 |
Correct |
71 ms |
133240 KB |
Output is correct |
19 |
Correct |
70 ms |
133240 KB |
Output is correct |
20 |
Correct |
71 ms |
133260 KB |
Output is correct |
21 |
Correct |
72 ms |
133248 KB |
Output is correct |
22 |
Correct |
72 ms |
133244 KB |
Output is correct |
23 |
Correct |
70 ms |
133240 KB |
Output is correct |
24 |
Correct |
72 ms |
133240 KB |
Output is correct |
25 |
Correct |
73 ms |
133240 KB |
Output is correct |
26 |
Correct |
71 ms |
133296 KB |
Output is correct |
27 |
Correct |
71 ms |
133240 KB |
Output is correct |
28 |
Correct |
71 ms |
133240 KB |
Output is correct |
29 |
Correct |
72 ms |
133368 KB |
Output is correct |
30 |
Correct |
73 ms |
133240 KB |
Output is correct |
31 |
Correct |
76 ms |
133240 KB |
Output is correct |
32 |
Correct |
72 ms |
133240 KB |
Output is correct |
33 |
Correct |
73 ms |
133240 KB |
Output is correct |
34 |
Correct |
72 ms |
133240 KB |
Output is correct |
35 |
Correct |
72 ms |
133240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
133240 KB |
Output is correct |
2 |
Correct |
71 ms |
133244 KB |
Output is correct |
3 |
Correct |
70 ms |
133368 KB |
Output is correct |
4 |
Correct |
72 ms |
133240 KB |
Output is correct |
5 |
Correct |
70 ms |
133240 KB |
Output is correct |
6 |
Correct |
71 ms |
133240 KB |
Output is correct |
7 |
Correct |
74 ms |
133240 KB |
Output is correct |
8 |
Correct |
73 ms |
133240 KB |
Output is correct |
9 |
Correct |
73 ms |
133240 KB |
Output is correct |
10 |
Correct |
74 ms |
133244 KB |
Output is correct |
11 |
Correct |
73 ms |
133240 KB |
Output is correct |
12 |
Correct |
72 ms |
133240 KB |
Output is correct |
13 |
Correct |
73 ms |
133272 KB |
Output is correct |
14 |
Correct |
72 ms |
133240 KB |
Output is correct |
15 |
Correct |
72 ms |
133240 KB |
Output is correct |
16 |
Correct |
72 ms |
133240 KB |
Output is correct |
17 |
Correct |
72 ms |
133248 KB |
Output is correct |
18 |
Correct |
103 ms |
133240 KB |
Output is correct |
19 |
Correct |
84 ms |
133244 KB |
Output is correct |
20 |
Correct |
75 ms |
133272 KB |
Output is correct |
21 |
Correct |
86 ms |
133240 KB |
Output is correct |
22 |
Correct |
88 ms |
133240 KB |
Output is correct |
23 |
Correct |
76 ms |
133240 KB |
Output is correct |
24 |
Correct |
73 ms |
133240 KB |
Output is correct |
25 |
Correct |
76 ms |
133240 KB |
Output is correct |
26 |
Correct |
73 ms |
133240 KB |
Output is correct |
27 |
Correct |
77 ms |
133196 KB |
Output is correct |
28 |
Correct |
73 ms |
133240 KB |
Output is correct |
29 |
Correct |
78 ms |
133240 KB |
Output is correct |
30 |
Correct |
73 ms |
133240 KB |
Output is correct |
31 |
Correct |
75 ms |
133240 KB |
Output is correct |
32 |
Correct |
73 ms |
133240 KB |
Output is correct |
33 |
Correct |
81 ms |
133240 KB |
Output is correct |
34 |
Correct |
73 ms |
133240 KB |
Output is correct |
35 |
Correct |
76 ms |
133240 KB |
Output is correct |
36 |
Correct |
72 ms |
133240 KB |
Output is correct |
37 |
Correct |
76 ms |
133240 KB |
Output is correct |
38 |
Correct |
72 ms |
133240 KB |
Output is correct |
39 |
Correct |
79 ms |
133240 KB |
Output is correct |
40 |
Correct |
76 ms |
133240 KB |
Output is correct |
41 |
Correct |
108 ms |
133240 KB |
Output is correct |
42 |
Correct |
91 ms |
133368 KB |
Output is correct |
43 |
Correct |
106 ms |
133172 KB |
Output is correct |
44 |
Correct |
92 ms |
133368 KB |
Output is correct |
45 |
Correct |
108 ms |
133240 KB |
Output is correct |
46 |
Correct |
93 ms |
133240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
133240 KB |
Output is correct |
2 |
Correct |
71 ms |
133244 KB |
Output is correct |
3 |
Correct |
70 ms |
133368 KB |
Output is correct |
4 |
Correct |
72 ms |
133240 KB |
Output is correct |
5 |
Correct |
70 ms |
133240 KB |
Output is correct |
6 |
Correct |
71 ms |
133240 KB |
Output is correct |
7 |
Correct |
74 ms |
133240 KB |
Output is correct |
8 |
Correct |
73 ms |
133240 KB |
Output is correct |
9 |
Correct |
73 ms |
133240 KB |
Output is correct |
10 |
Correct |
74 ms |
133244 KB |
Output is correct |
11 |
Correct |
73 ms |
133240 KB |
Output is correct |
12 |
Correct |
72 ms |
133240 KB |
Output is correct |
13 |
Correct |
73 ms |
133272 KB |
Output is correct |
14 |
Correct |
72 ms |
133240 KB |
Output is correct |
15 |
Correct |
72 ms |
133240 KB |
Output is correct |
16 |
Correct |
72 ms |
133240 KB |
Output is correct |
17 |
Correct |
72 ms |
133248 KB |
Output is correct |
18 |
Correct |
71 ms |
133240 KB |
Output is correct |
19 |
Correct |
70 ms |
133240 KB |
Output is correct |
20 |
Correct |
71 ms |
133260 KB |
Output is correct |
21 |
Correct |
72 ms |
133248 KB |
Output is correct |
22 |
Correct |
72 ms |
133244 KB |
Output is correct |
23 |
Correct |
70 ms |
133240 KB |
Output is correct |
24 |
Correct |
72 ms |
133240 KB |
Output is correct |
25 |
Correct |
73 ms |
133240 KB |
Output is correct |
26 |
Correct |
71 ms |
133296 KB |
Output is correct |
27 |
Correct |
71 ms |
133240 KB |
Output is correct |
28 |
Correct |
71 ms |
133240 KB |
Output is correct |
29 |
Correct |
72 ms |
133368 KB |
Output is correct |
30 |
Correct |
73 ms |
133240 KB |
Output is correct |
31 |
Correct |
76 ms |
133240 KB |
Output is correct |
32 |
Correct |
72 ms |
133240 KB |
Output is correct |
33 |
Correct |
73 ms |
133240 KB |
Output is correct |
34 |
Correct |
72 ms |
133240 KB |
Output is correct |
35 |
Correct |
72 ms |
133240 KB |
Output is correct |
36 |
Correct |
103 ms |
133240 KB |
Output is correct |
37 |
Correct |
84 ms |
133244 KB |
Output is correct |
38 |
Correct |
75 ms |
133272 KB |
Output is correct |
39 |
Correct |
86 ms |
133240 KB |
Output is correct |
40 |
Correct |
88 ms |
133240 KB |
Output is correct |
41 |
Correct |
76 ms |
133240 KB |
Output is correct |
42 |
Correct |
73 ms |
133240 KB |
Output is correct |
43 |
Correct |
76 ms |
133240 KB |
Output is correct |
44 |
Correct |
73 ms |
133240 KB |
Output is correct |
45 |
Correct |
77 ms |
133196 KB |
Output is correct |
46 |
Correct |
73 ms |
133240 KB |
Output is correct |
47 |
Correct |
78 ms |
133240 KB |
Output is correct |
48 |
Correct |
73 ms |
133240 KB |
Output is correct |
49 |
Correct |
75 ms |
133240 KB |
Output is correct |
50 |
Correct |
73 ms |
133240 KB |
Output is correct |
51 |
Correct |
81 ms |
133240 KB |
Output is correct |
52 |
Correct |
73 ms |
133240 KB |
Output is correct |
53 |
Correct |
76 ms |
133240 KB |
Output is correct |
54 |
Correct |
72 ms |
133240 KB |
Output is correct |
55 |
Correct |
76 ms |
133240 KB |
Output is correct |
56 |
Correct |
72 ms |
133240 KB |
Output is correct |
57 |
Correct |
79 ms |
133240 KB |
Output is correct |
58 |
Correct |
76 ms |
133240 KB |
Output is correct |
59 |
Correct |
108 ms |
133240 KB |
Output is correct |
60 |
Correct |
91 ms |
133368 KB |
Output is correct |
61 |
Correct |
106 ms |
133172 KB |
Output is correct |
62 |
Correct |
92 ms |
133368 KB |
Output is correct |
63 |
Correct |
108 ms |
133240 KB |
Output is correct |
64 |
Correct |
93 ms |
133240 KB |
Output is correct |
65 |
Correct |
104 ms |
133240 KB |
Output is correct |
66 |
Correct |
100 ms |
133240 KB |
Output is correct |
67 |
Correct |
96 ms |
133240 KB |
Output is correct |
68 |
Correct |
97 ms |
133240 KB |
Output is correct |
69 |
Correct |
104 ms |
133240 KB |
Output is correct |
70 |
Correct |
104 ms |
133240 KB |
Output is correct |
71 |
Correct |
101 ms |
133240 KB |
Output is correct |
72 |
Correct |
102 ms |
133240 KB |
Output is correct |
73 |
Correct |
98 ms |
133240 KB |
Output is correct |
74 |
Correct |
97 ms |
133240 KB |
Output is correct |
75 |
Correct |
99 ms |
133240 KB |
Output is correct |
76 |
Correct |
109 ms |
133296 KB |
Output is correct |
77 |
Correct |
107 ms |
133240 KB |
Output is correct |
78 |
Correct |
94 ms |
133368 KB |
Output is correct |
79 |
Correct |
96 ms |
133240 KB |
Output is correct |
80 |
Correct |
105 ms |
133240 KB |
Output is correct |
81 |
Correct |
96 ms |
133240 KB |
Output is correct |
82 |
Correct |
99 ms |
133240 KB |
Output is correct |
83 |
Correct |
107 ms |
133240 KB |
Output is correct |
84 |
Correct |
100 ms |
133240 KB |
Output is correct |
85 |
Correct |
105 ms |
133240 KB |
Output is correct |
86 |
Correct |
107 ms |
133368 KB |
Output is correct |
87 |
Correct |
103 ms |
133216 KB |
Output is correct |
88 |
Correct |
108 ms |
133240 KB |
Output is correct |
89 |
Correct |
111 ms |
133220 KB |
Output is correct |
90 |
Correct |
98 ms |
133240 KB |
Output is correct |
91 |
Correct |
107 ms |
133240 KB |
Output is correct |
92 |
Correct |
107 ms |
133240 KB |
Output is correct |
93 |
Correct |
105 ms |
133240 KB |
Output is correct |