This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int inf=1e9+2;
int dp[201][201][201][2];
int x[201],t[201],y[201];
int n;
int run(int pos){
if (pos==0)return n;
return pos-1;
}
int nur(int pos){
if (pos==n)return 0;
return pos+1;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
long long l;
cin>>n>>l;
for1(i,1,n){
cin>>x[i];
y[i]=l-x[i];
}
for1(i,1,n){
cin>>t[i];
}
for1(i,0,n){
for1(j,0,n){
for1(k,0,n){
dp[i][j][k][0]=dp[i][j][k][1]=inf;
}
}
}
dp[0][0][0][0]=dp[0][0][0][1]=0;
//cout<<dp[0][1][2][0]<<'\n';
for1(i,0,0){
for1(j,0,n){
if (i!=0&&i<j)continue;
for2(k,n,0){
for1(turn,0,1){
if (dp[i][j][k][turn]>=inf)continue;
if (i==j&&i!=0)continue;
if (j==n)continue;
if (i==1)continue;
//cout<<k<<'\n';
//cout<<i<<" "<<j<<" "<<k<<" "<<turn<<" "<<dp[i][j][k][turn]<<'\n';
if (turn){
//on i
//go i
int nxt=run(i);
int newcost,newk;
if (nxt!=j){
newcost=min(inf,dp[i][j][k][turn]+y[nxt]-y[i]);
newk=k;
if (newcost<=t[nxt])newk++;
dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
}
//go j
nxt=nur(j);
if (nxt!=i){
newcost=min(inf,dp[i][j][k][turn]+y[i]+x[nxt]);
newk=k;
if (newcost<=t[nxt])newk++;
dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
}
}
else {
//on j
//go i
int nxt=run(i),newcost,newk;
if (nxt!=j){
newcost=min(inf,dp[i][j][k][turn]+x[j]+y[nxt]);
newk=k;
if (newcost<=t[nxt])newk++;
dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
}
//go j
nxt=nur(j);
if (nxt!=i){
newk=k;
newcost=min(inf,dp[i][j][k][turn]+x[nxt]-x[j]);
if (newcost<=t[nxt])newk++;
dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
}
}
}
}
}
}
//cout<<dp[0][1][2][0];
for2(i,n,1){
for1(j,0,n){
if (i!=0&&i<j)continue;
for2(k,n,0){
for1(turn,0,1){
if (dp[i][j][k][turn]>=inf)continue;
if (i==j&&i!=0)continue;
if (j==n)continue;
if (i==1)continue;
if (turn){
//on i
//go i
int nxt=run(i);
int newcost,newk;
if (nxt!=j){
newcost=min(inf,dp[i][j][k][turn]+y[nxt]-y[i]);
newk=k;
if (newcost<=t[nxt])newk++;
dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
}
//go j
nxt=nur(j);
if (nxt!=i){
newcost=min(inf,dp[i][j][k][turn]+y[i]+x[nxt]);
newk=k;
if (newcost<=t[nxt])newk++;
dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
}
}
else {
//on j
//go i
int nxt=run(i),newcost,newk;
if (nxt!=j){
newcost=min(inf,dp[i][j][k][turn]+x[j]+y[nxt]);
newk=k;
if (newcost<=t[nxt])newk++;
dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
}
//go j
nxt=nur(j);
if (nxt!=i){
newk=k;
newcost=min(inf,dp[i][j][k][turn]+x[nxt]-x[j]);
if (newcost<=t[nxt])newk++;
dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
}
}
}
}
}
}
int ans=0;
for1(i,0,n){
for1(j,0,n){
for1(k,1,n){
for1(l1,0,1){
if (dp[i][j][k][l1]>=inf)continue;
ans=max(ans,k);
//if (k==12)cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k][l1]<<'\n';
}
}
}
}
cout<<ans;
//cout<<dp[0][1][1][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... |