///
/// Let the voice of love take you higher!
///
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x, l, r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
typedef std::pair<ll ,ll > pll;
using namespace std;
#define int ll
const int N = 210;
ll dp[2][N][N][N]; // d, cnt, l, r
ll len, _x[N], *x = _x+1;
ll _t[N], *t = _t+1;
int n;
ll dis(int i, int j)
{
return min(abs(x[j]-x[i]), len-abs(x[j]-x[i]));
}
bool gd(int i, int j, ll t)
{
if(t > 1e10) return 0;
return dis(i,j)+t <= ::t[j];
}
void smin(ll& x, ll y){x = min(x, y);}
signed main()
{
FAST;
cin >> n >> len;
Loop(i,0,n) cin >> x[i];
x[n] = x[0]; x[-1] = x[n-1];
Loop(i,0,n) cin >> t[i];
t[n] = t[0]; t[-1] = t[n-1];
memset(dp, 31, sizeof dp);
dp[0][t[0 ]>= x[ 0]][1][n ] = x[ 0];
dp[0][t[0 ]>= x[ 0]][1][n ] = x[ 0];
dp[1][t[n-1]>=len-x[n-1]][0][n-1] = len-x[n-1];
dp[1][t[n-1]>=len-x[n-1]][0][n-1] = len-x[n-1];
LoopR(k,1,n)
{
Loop(l,0,n-k+1)
{
int r = l+k;
Loop(cnt,0,n)
{
smin(dp[0][cnt+gd(l-1,l ,dp[0][cnt][l][r])][l+1][r], dp[0][cnt][l][r]+dis(l-1,l ));
smin(dp[1][cnt+gd(l-1,r-1,dp[0][cnt][l][r])][l][r-1], dp[0][cnt][l][r]+dis(l-1,r-1));
smin(dp[0][cnt+gd(r ,l ,dp[1][cnt][l][r])][l+1][r], dp[1][cnt][l][r]+dis(r ,l ));
smin(dp[1][cnt+gd(r ,r-1,dp[1][cnt][l][r])][l][r-1], dp[1][cnt][l][r]+dis(r ,r-1));
}
}
}
int ans = 0;
Loop(i,0,n+1) Loop(cnt,ans+1,n+1)
{
if(dp[0][cnt][i][i] < 1e10) ans = cnt;
if(dp[1][cnt][i][i] < 1e10) ans = cnt;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
145216 KB |
Output is correct |
2 |
Correct |
55 ms |
145188 KB |
Output is correct |
3 |
Correct |
59 ms |
145200 KB |
Output is correct |
4 |
Correct |
58 ms |
145268 KB |
Output is correct |
5 |
Correct |
54 ms |
145172 KB |
Output is correct |
6 |
Correct |
61 ms |
145232 KB |
Output is correct |
7 |
Correct |
60 ms |
145272 KB |
Output is correct |
8 |
Correct |
54 ms |
145268 KB |
Output is correct |
9 |
Correct |
55 ms |
145220 KB |
Output is correct |
10 |
Correct |
55 ms |
145172 KB |
Output is correct |
11 |
Correct |
55 ms |
145308 KB |
Output is correct |
12 |
Correct |
55 ms |
145268 KB |
Output is correct |
13 |
Correct |
59 ms |
145220 KB |
Output is correct |
14 |
Correct |
55 ms |
145256 KB |
Output is correct |
15 |
Correct |
63 ms |
145216 KB |
Output is correct |
16 |
Correct |
60 ms |
145200 KB |
Output is correct |
17 |
Correct |
57 ms |
145192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
145216 KB |
Output is correct |
2 |
Correct |
55 ms |
145188 KB |
Output is correct |
3 |
Correct |
59 ms |
145200 KB |
Output is correct |
4 |
Correct |
58 ms |
145268 KB |
Output is correct |
5 |
Correct |
54 ms |
145172 KB |
Output is correct |
6 |
Correct |
61 ms |
145232 KB |
Output is correct |
7 |
Correct |
60 ms |
145272 KB |
Output is correct |
8 |
Correct |
54 ms |
145268 KB |
Output is correct |
9 |
Correct |
55 ms |
145220 KB |
Output is correct |
10 |
Correct |
55 ms |
145172 KB |
Output is correct |
11 |
Correct |
55 ms |
145308 KB |
Output is correct |
12 |
Correct |
55 ms |
145268 KB |
Output is correct |
13 |
Correct |
59 ms |
145220 KB |
Output is correct |
14 |
Correct |
55 ms |
145256 KB |
Output is correct |
15 |
Correct |
63 ms |
145216 KB |
Output is correct |
16 |
Correct |
60 ms |
145200 KB |
Output is correct |
17 |
Correct |
57 ms |
145192 KB |
Output is correct |
18 |
Correct |
58 ms |
145264 KB |
Output is correct |
19 |
Correct |
55 ms |
145220 KB |
Output is correct |
20 |
Correct |
59 ms |
145248 KB |
Output is correct |
21 |
Correct |
55 ms |
145256 KB |
Output is correct |
22 |
Correct |
58 ms |
145220 KB |
Output is correct |
23 |
Correct |
66 ms |
145256 KB |
Output is correct |
24 |
Correct |
54 ms |
145220 KB |
Output is correct |
25 |
Correct |
55 ms |
145220 KB |
Output is correct |
26 |
Correct |
63 ms |
145232 KB |
Output is correct |
27 |
Correct |
59 ms |
145280 KB |
Output is correct |
28 |
Correct |
60 ms |
145168 KB |
Output is correct |
29 |
Correct |
60 ms |
145272 KB |
Output is correct |
30 |
Correct |
58 ms |
145168 KB |
Output is correct |
31 |
Correct |
60 ms |
145168 KB |
Output is correct |
32 |
Correct |
55 ms |
145280 KB |
Output is correct |
33 |
Correct |
55 ms |
145216 KB |
Output is correct |
34 |
Correct |
63 ms |
145176 KB |
Output is correct |
35 |
Correct |
61 ms |
145196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
145216 KB |
Output is correct |
2 |
Correct |
55 ms |
145188 KB |
Output is correct |
3 |
Correct |
59 ms |
145200 KB |
Output is correct |
4 |
Correct |
58 ms |
145268 KB |
Output is correct |
5 |
Correct |
54 ms |
145172 KB |
Output is correct |
6 |
Correct |
61 ms |
145232 KB |
Output is correct |
7 |
Correct |
60 ms |
145272 KB |
Output is correct |
8 |
Correct |
54 ms |
145268 KB |
Output is correct |
9 |
Correct |
55 ms |
145220 KB |
Output is correct |
10 |
Correct |
55 ms |
145172 KB |
Output is correct |
11 |
Correct |
55 ms |
145308 KB |
Output is correct |
12 |
Correct |
55 ms |
145268 KB |
Output is correct |
13 |
Correct |
59 ms |
145220 KB |
Output is correct |
14 |
Correct |
55 ms |
145256 KB |
Output is correct |
15 |
Correct |
63 ms |
145216 KB |
Output is correct |
16 |
Correct |
60 ms |
145200 KB |
Output is correct |
17 |
Correct |
57 ms |
145192 KB |
Output is correct |
18 |
Correct |
291 ms |
145284 KB |
Output is correct |
19 |
Correct |
123 ms |
145292 KB |
Output is correct |
20 |
Correct |
86 ms |
145272 KB |
Output is correct |
21 |
Correct |
139 ms |
145240 KB |
Output is correct |
22 |
Correct |
163 ms |
145284 KB |
Output is correct |
23 |
Correct |
74 ms |
145288 KB |
Output is correct |
24 |
Correct |
74 ms |
145224 KB |
Output is correct |
25 |
Correct |
76 ms |
145220 KB |
Output is correct |
26 |
Correct |
68 ms |
145296 KB |
Output is correct |
27 |
Correct |
88 ms |
145164 KB |
Output is correct |
28 |
Correct |
72 ms |
145184 KB |
Output is correct |
29 |
Correct |
84 ms |
145252 KB |
Output is correct |
30 |
Correct |
73 ms |
145240 KB |
Output is correct |
31 |
Correct |
74 ms |
145232 KB |
Output is correct |
32 |
Correct |
69 ms |
145220 KB |
Output is correct |
33 |
Correct |
77 ms |
145312 KB |
Output is correct |
34 |
Correct |
61 ms |
145268 KB |
Output is correct |
35 |
Correct |
83 ms |
145196 KB |
Output is correct |
36 |
Correct |
60 ms |
145344 KB |
Output is correct |
37 |
Correct |
71 ms |
145248 KB |
Output is correct |
38 |
Correct |
61 ms |
145212 KB |
Output is correct |
39 |
Correct |
84 ms |
145284 KB |
Output is correct |
40 |
Correct |
68 ms |
145244 KB |
Output is correct |
41 |
Correct |
341 ms |
145344 KB |
Output is correct |
42 |
Correct |
207 ms |
145220 KB |
Output is correct |
43 |
Correct |
366 ms |
145284 KB |
Output is correct |
44 |
Correct |
154 ms |
145220 KB |
Output is correct |
45 |
Correct |
404 ms |
145284 KB |
Output is correct |
46 |
Correct |
222 ms |
145396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
145216 KB |
Output is correct |
2 |
Correct |
55 ms |
145188 KB |
Output is correct |
3 |
Correct |
59 ms |
145200 KB |
Output is correct |
4 |
Correct |
58 ms |
145268 KB |
Output is correct |
5 |
Correct |
54 ms |
145172 KB |
Output is correct |
6 |
Correct |
61 ms |
145232 KB |
Output is correct |
7 |
Correct |
60 ms |
145272 KB |
Output is correct |
8 |
Correct |
54 ms |
145268 KB |
Output is correct |
9 |
Correct |
55 ms |
145220 KB |
Output is correct |
10 |
Correct |
55 ms |
145172 KB |
Output is correct |
11 |
Correct |
55 ms |
145308 KB |
Output is correct |
12 |
Correct |
55 ms |
145268 KB |
Output is correct |
13 |
Correct |
59 ms |
145220 KB |
Output is correct |
14 |
Correct |
55 ms |
145256 KB |
Output is correct |
15 |
Correct |
63 ms |
145216 KB |
Output is correct |
16 |
Correct |
60 ms |
145200 KB |
Output is correct |
17 |
Correct |
57 ms |
145192 KB |
Output is correct |
18 |
Correct |
58 ms |
145264 KB |
Output is correct |
19 |
Correct |
55 ms |
145220 KB |
Output is correct |
20 |
Correct |
59 ms |
145248 KB |
Output is correct |
21 |
Correct |
55 ms |
145256 KB |
Output is correct |
22 |
Correct |
58 ms |
145220 KB |
Output is correct |
23 |
Correct |
66 ms |
145256 KB |
Output is correct |
24 |
Correct |
54 ms |
145220 KB |
Output is correct |
25 |
Correct |
55 ms |
145220 KB |
Output is correct |
26 |
Correct |
63 ms |
145232 KB |
Output is correct |
27 |
Correct |
59 ms |
145280 KB |
Output is correct |
28 |
Correct |
60 ms |
145168 KB |
Output is correct |
29 |
Correct |
60 ms |
145272 KB |
Output is correct |
30 |
Correct |
58 ms |
145168 KB |
Output is correct |
31 |
Correct |
60 ms |
145168 KB |
Output is correct |
32 |
Correct |
55 ms |
145280 KB |
Output is correct |
33 |
Correct |
55 ms |
145216 KB |
Output is correct |
34 |
Correct |
63 ms |
145176 KB |
Output is correct |
35 |
Correct |
61 ms |
145196 KB |
Output is correct |
36 |
Correct |
291 ms |
145284 KB |
Output is correct |
37 |
Correct |
123 ms |
145292 KB |
Output is correct |
38 |
Correct |
86 ms |
145272 KB |
Output is correct |
39 |
Correct |
139 ms |
145240 KB |
Output is correct |
40 |
Correct |
163 ms |
145284 KB |
Output is correct |
41 |
Correct |
74 ms |
145288 KB |
Output is correct |
42 |
Correct |
74 ms |
145224 KB |
Output is correct |
43 |
Correct |
76 ms |
145220 KB |
Output is correct |
44 |
Correct |
68 ms |
145296 KB |
Output is correct |
45 |
Correct |
88 ms |
145164 KB |
Output is correct |
46 |
Correct |
72 ms |
145184 KB |
Output is correct |
47 |
Correct |
84 ms |
145252 KB |
Output is correct |
48 |
Correct |
73 ms |
145240 KB |
Output is correct |
49 |
Correct |
74 ms |
145232 KB |
Output is correct |
50 |
Correct |
69 ms |
145220 KB |
Output is correct |
51 |
Correct |
77 ms |
145312 KB |
Output is correct |
52 |
Correct |
61 ms |
145268 KB |
Output is correct |
53 |
Correct |
83 ms |
145196 KB |
Output is correct |
54 |
Correct |
60 ms |
145344 KB |
Output is correct |
55 |
Correct |
71 ms |
145248 KB |
Output is correct |
56 |
Correct |
61 ms |
145212 KB |
Output is correct |
57 |
Correct |
84 ms |
145284 KB |
Output is correct |
58 |
Correct |
68 ms |
145244 KB |
Output is correct |
59 |
Correct |
341 ms |
145344 KB |
Output is correct |
60 |
Correct |
207 ms |
145220 KB |
Output is correct |
61 |
Correct |
366 ms |
145284 KB |
Output is correct |
62 |
Correct |
154 ms |
145220 KB |
Output is correct |
63 |
Correct |
404 ms |
145284 KB |
Output is correct |
64 |
Correct |
222 ms |
145396 KB |
Output is correct |
65 |
Correct |
298 ms |
145208 KB |
Output is correct |
66 |
Correct |
284 ms |
145220 KB |
Output is correct |
67 |
Correct |
215 ms |
145232 KB |
Output is correct |
68 |
Correct |
202 ms |
145180 KB |
Output is correct |
69 |
Correct |
291 ms |
145340 KB |
Output is correct |
70 |
Correct |
335 ms |
145284 KB |
Output is correct |
71 |
Correct |
260 ms |
145224 KB |
Output is correct |
72 |
Correct |
309 ms |
145408 KB |
Output is correct |
73 |
Correct |
242 ms |
145292 KB |
Output is correct |
74 |
Correct |
244 ms |
145228 KB |
Output is correct |
75 |
Correct |
233 ms |
145228 KB |
Output is correct |
76 |
Correct |
343 ms |
145288 KB |
Output is correct |
77 |
Correct |
305 ms |
145212 KB |
Output is correct |
78 |
Correct |
240 ms |
145292 KB |
Output is correct |
79 |
Correct |
246 ms |
145220 KB |
Output is correct |
80 |
Correct |
291 ms |
145188 KB |
Output is correct |
81 |
Correct |
222 ms |
145216 KB |
Output is correct |
82 |
Correct |
216 ms |
145288 KB |
Output is correct |
83 |
Correct |
357 ms |
145348 KB |
Output is correct |
84 |
Correct |
254 ms |
145292 KB |
Output is correct |
85 |
Correct |
339 ms |
145288 KB |
Output is correct |
86 |
Correct |
312 ms |
145388 KB |
Output is correct |
87 |
Correct |
245 ms |
145284 KB |
Output is correct |
88 |
Correct |
395 ms |
145288 KB |
Output is correct |
89 |
Correct |
407 ms |
145352 KB |
Output is correct |
90 |
Correct |
225 ms |
145288 KB |
Output is correct |
91 |
Correct |
368 ms |
145288 KB |
Output is correct |
92 |
Correct |
390 ms |
145220 KB |
Output is correct |
93 |
Correct |
331 ms |
145308 KB |
Output is correct |