#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
//#define int ll
int n, l, x[201], t[201];
int dp[202][202][202][2];
int32_t main(){
INIT
cin>>n>>l;
for(int i=1; i<=n; i++){
cin>>x[i];
}
for(int i=1; i<=n; i++){
cin>>t[i];
}
int res=0;
x[n+1]=l;
for(int cnt=0; cnt<=n; cnt++){
for(int i=(n+1); i>=1; i--){
for(int j=0; j<i; j++){
if( (dp[cnt][i][j][1]!=0) ){
dp[cnt][i][j][0]=(dp[cnt][i][j][0]==0 )?(dp[cnt][i][j][1]+(l-x[i]+x[j]) ):( min(dp[cnt][i][j][0], dp[cnt][i][j][1]+l-x[i]+x[j]) );
}
if( (dp[cnt][i][j][0]!=0) || ( (i==(n+1)) && (j==0 ) && (cnt==0) ) ){
res=max(res, cnt);
if( (dp[cnt][i][j][0]+x[j+1]-x[j])<=t[j+1] ){
dp[cnt+1][i][j+1][0]=(dp[cnt+1][i][j+1][0]==0)?( (dp[cnt][i][j][0]+x[j+1]-x[j]) ):( min((dp[cnt][i][j][0]+x[j+1]-x[j]), dp[cnt+1][i][j+1][0] ) );
}
else{
dp[cnt][i][j+1][0]=(dp[cnt][i][j+1][0]==0 )?( dp[cnt][i][j][0]+x[j+1]-x[j] ):(min(dp[cnt][i][j+1][0], dp[cnt][i][j][0]+x[j+1]-x[j] ) );
}
}
if(dp[cnt][i][j][0]!=0){
dp[cnt][i][j][1]=(dp[cnt][i][j][1]==0 )?(dp[cnt][i][j][0]+l-x[i]+x[j] ):(min(dp[cnt][i][j][1], dp[cnt][i][j][0]+l-x[i]+x[j] ) );
}
if( (dp[cnt][i][j][1]!=0) || ( (i==(n+1)) && (j==0) && (cnt==0) ) ){
res=max(res, cnt);
if(dp[cnt][i][j][0]!=0){
dp[cnt][i][j][1]=(dp[cnt][i][j][1]==0 )?(dp[cnt][i][j][0]+l-x[i]+x[j] ):(min(dp[cnt][i][j][1], dp[cnt][i][j][0]+l-x[i]+x[j] ) );
}
if( ( dp[cnt][i][j][1]+x[i]-x[i-1] )<=t[i-1] ){
dp[cnt+1][i-1][j][1]=(dp[cnt+1][i-1][j][1]==0 )?(dp[cnt][i][j][1]+x[i]-x[i-1] ):(min(dp[cnt][i][j][1]+x[i]-x[i-1], dp[cnt+1][i-1][j][1] ) );
}
else{
dp[cnt][i-1][j][1]=(dp[cnt][i-1][j][1]==0)?(dp[cnt][i][j][1]+x[i]-x[i-1] ):(min(dp[cnt][i-1][j][1], dp[cnt][i][j][1]+x[i]-x[i-1]) );
}
}
//cout<<"cnt="<<cnt<<" i="<<i<<" j="<<j<<" dp0="<<dp[cnt][i][j][0]<<" dp1="<<dp[cnt][i][j][1]<<"\n";
}
}
}
cout<<res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
18 |
Incorrect |
0 ms |
588 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
18 |
Correct |
25 ms |
18508 KB |
Output is correct |
19 |
Correct |
15 ms |
14028 KB |
Output is correct |
20 |
Correct |
9 ms |
6600 KB |
Output is correct |
21 |
Correct |
14 ms |
11340 KB |
Output is correct |
22 |
Correct |
20 ms |
16460 KB |
Output is correct |
23 |
Correct |
6 ms |
7852 KB |
Output is correct |
24 |
Correct |
4 ms |
3276 KB |
Output is correct |
25 |
Correct |
6 ms |
7752 KB |
Output is correct |
26 |
Correct |
2 ms |
1996 KB |
Output is correct |
27 |
Correct |
7 ms |
8140 KB |
Output is correct |
28 |
Correct |
3 ms |
3148 KB |
Output is correct |
29 |
Correct |
6 ms |
6884 KB |
Output is correct |
30 |
Correct |
4 ms |
3532 KB |
Output is correct |
31 |
Correct |
6 ms |
6220 KB |
Output is correct |
32 |
Correct |
3 ms |
3660 KB |
Output is correct |
33 |
Correct |
7 ms |
6220 KB |
Output is correct |
34 |
Correct |
2 ms |
1996 KB |
Output is correct |
35 |
Correct |
4 ms |
1740 KB |
Output is correct |
36 |
Correct |
2 ms |
2252 KB |
Output is correct |
37 |
Correct |
4 ms |
1996 KB |
Output is correct |
38 |
Correct |
4 ms |
3148 KB |
Output is correct |
39 |
Correct |
4 ms |
1996 KB |
Output is correct |
40 |
Correct |
3 ms |
2508 KB |
Output is correct |
41 |
Correct |
37 ms |
28920 KB |
Output is correct |
42 |
Correct |
11 ms |
588 KB |
Output is correct |
43 |
Correct |
36 ms |
30140 KB |
Output is correct |
44 |
Correct |
10 ms |
588 KB |
Output is correct |
45 |
Correct |
36 ms |
29628 KB |
Output is correct |
46 |
Correct |
12 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
18 |
Incorrect |
0 ms |
588 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |