This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3","unroll-loops")
#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
ll l;
cin>>n>>l;
vector<ll> pos(n+1),t(n+1);
for(int i=1;i<=n;i++) cin>>pos[i];
for(int i=1;i<=n;i++) cin>>t[i];
ll dp[201][201][201][2];
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
for(int r=0;r<2;r++) dp[i][j][k][r]=1e18;
}
}
}
dp[0][0][0][0]=0;
dp[0][0][0][1]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k+=(k!=0?1:j+1)){
for(int r=j-1;r>=0;r--){
if(dp[i-1][r][k][0]+pos[j]-pos[r]<=t[j]){
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][r][k][0]+pos[j]-pos[r]);
}
if(dp[i-1][r][k][1]+pos[j]+l-pos[k]<=t[j]){
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][r][k][1]+pos[j]+l-pos[k]);
}
}
for(int r=k+1;r<=n;r++){
if(dp[i-1][j][r][1]+pos[r]-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<dp[i-1][j][r][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][r][1]+pos[r]-pos[k]);
}
if(dp[i-1][j][r][0]+pos[j]+l-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<dp[i-1][j][r][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][r][0]+pos[j]+l-pos[k]);
}
}
if(dp[i-1][j][0][1]+pos[0]+l-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<dp[i-1][j][0][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][0][1]+pos[0]+l-pos[k]);
}
if(dp[i-1][j][0][0]+pos[j]+l-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<"hehe"<<dp[i-1][j][0][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][0][0]+pos[j]+l-pos[k]);
}
}
}
}
for(int i=n;i>=0;i--){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
for(int r=0;r<=1;r++){
if(dp[i][j][k][r]<1e18){
cout<<i;
return 0;
}
}
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |