#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=210;
int dp[N][N][N][2];
const int INF=1e15;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, tot;
cin >> n >> tot;
vector<int> x(n+2);
x[0]=0; x[n+1]=tot;
for(int i=1; i<=n; i++){
cin >> x[i];
}
vector<int> t(n+2);
t[0]=-1; t[n+1]=-1;
for(int i=1; i<=n; i++){
cin >> t[i];
}
//initialize
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
for(int k=0; k<N; k++){
for(int x=0; x<2; x++){
dp[i][j][k][x]=INF;
}
}
}
}
dp[0][0][0][0]=0;
dp[0][0][0][1]=0;
for(int l=0; l<=n; l++){
for(int r=0; r<=n; r++){
if(l+r>n) continue;
for(int c=0; c<=n; c++){
for(int loc=0; loc<2; loc++){
int cor;
if(loc==0){
cor = x[n+1-l];
}
else{
cor = x[r];
}
//walk right
int distright = 0;
if(loc==0){
distright = (tot-cor) + x[r+1];
}
else{
distright = x[r+1] - cor;
}
dp[l][r+1][c][1] = min(dp[l][r+1][c][1], dp[l][r][c][loc] + distright);
dp[l][r+1][c][0] = min(dp[l][r+1][c][0], dp[l][r][c][loc] + 2*distright);
if( dp[l][r][c][loc] + distright <= t[r+1] ){
dp[l][r+1][c+1][1] = min( dp[l][r+1][c+1][1], dp[l][r][c][loc] + distright );
dp[l][r+1][c+1][0] = min( dp[l][r+1][c+1][0], dp[l][r][c][loc] + 2*distright);
}
//walk left
int distleft=0;
if(loc==0){
distleft = cor - x[n+1 - (l+1)];
}
else{
distleft = tot - x[n+1 - (l+1)] + cor;
}
dp[l+1][r][c][0] = min(dp[l+1][r][c][0], dp[l][r][c][loc] + distleft);
dp[l+1][r][c][1] = min(dp[l+1][r][c][1], dp[l][r][c][loc] + 2*distleft);
if( dp[l][r][c][loc] + distleft <= t[n+1-(l+1)]){
dp[l+1][r][c+1][0] = min(dp[l+1][r][c+1][0], dp[l][r][c][loc] + distleft);
dp[l+1][r][c+1][1] = min(dp[l+1][r][c+1][1], dp[l][r][c][loc] + 2*distleft);
}
}
}
}
}
//finding the largest one
int ans=0;
for(int i=0; i<=n; i++){
for(int j=0; j<=n; j++){
for(int k=0; k<=n; k++){
//cout << i << " " << j << " " << k << ": " << dp[i][j][k][0] << ", " << dp[i][j][k][1] << "\n";
for(int x=0; x<2; x++){
if(dp[i][j][k][x] != INF){
ans = max(ans, k);
}
}
}
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
145356 KB |
Output is correct |
2 |
Correct |
69 ms |
145172 KB |
Output is correct |
3 |
Correct |
60 ms |
145180 KB |
Output is correct |
4 |
Correct |
65 ms |
145268 KB |
Output is correct |
5 |
Correct |
61 ms |
145352 KB |
Output is correct |
6 |
Correct |
63 ms |
145228 KB |
Output is correct |
7 |
Correct |
65 ms |
145208 KB |
Output is correct |
8 |
Correct |
64 ms |
145284 KB |
Output is correct |
9 |
Correct |
60 ms |
145184 KB |
Output is correct |
10 |
Correct |
75 ms |
145180 KB |
Output is correct |
11 |
Correct |
64 ms |
145204 KB |
Output is correct |
12 |
Correct |
63 ms |
145224 KB |
Output is correct |
13 |
Incorrect |
68 ms |
145276 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
145356 KB |
Output is correct |
2 |
Correct |
69 ms |
145172 KB |
Output is correct |
3 |
Correct |
60 ms |
145180 KB |
Output is correct |
4 |
Correct |
65 ms |
145268 KB |
Output is correct |
5 |
Correct |
61 ms |
145352 KB |
Output is correct |
6 |
Correct |
63 ms |
145228 KB |
Output is correct |
7 |
Correct |
65 ms |
145208 KB |
Output is correct |
8 |
Correct |
64 ms |
145284 KB |
Output is correct |
9 |
Correct |
60 ms |
145184 KB |
Output is correct |
10 |
Correct |
75 ms |
145180 KB |
Output is correct |
11 |
Correct |
64 ms |
145204 KB |
Output is correct |
12 |
Correct |
63 ms |
145224 KB |
Output is correct |
13 |
Incorrect |
68 ms |
145276 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
145356 KB |
Output is correct |
2 |
Correct |
69 ms |
145172 KB |
Output is correct |
3 |
Correct |
60 ms |
145180 KB |
Output is correct |
4 |
Correct |
65 ms |
145268 KB |
Output is correct |
5 |
Correct |
61 ms |
145352 KB |
Output is correct |
6 |
Correct |
63 ms |
145228 KB |
Output is correct |
7 |
Correct |
65 ms |
145208 KB |
Output is correct |
8 |
Correct |
64 ms |
145284 KB |
Output is correct |
9 |
Correct |
60 ms |
145184 KB |
Output is correct |
10 |
Correct |
75 ms |
145180 KB |
Output is correct |
11 |
Correct |
64 ms |
145204 KB |
Output is correct |
12 |
Correct |
63 ms |
145224 KB |
Output is correct |
13 |
Incorrect |
68 ms |
145276 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
145356 KB |
Output is correct |
2 |
Correct |
69 ms |
145172 KB |
Output is correct |
3 |
Correct |
60 ms |
145180 KB |
Output is correct |
4 |
Correct |
65 ms |
145268 KB |
Output is correct |
5 |
Correct |
61 ms |
145352 KB |
Output is correct |
6 |
Correct |
63 ms |
145228 KB |
Output is correct |
7 |
Correct |
65 ms |
145208 KB |
Output is correct |
8 |
Correct |
64 ms |
145284 KB |
Output is correct |
9 |
Correct |
60 ms |
145184 KB |
Output is correct |
10 |
Correct |
75 ms |
145180 KB |
Output is correct |
11 |
Correct |
64 ms |
145204 KB |
Output is correct |
12 |
Correct |
63 ms |
145224 KB |
Output is correct |
13 |
Incorrect |
68 ms |
145276 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |