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 ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
if(x<y)
{
x=y;
return 1;
}
return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
if(x>y)
{
x=y;
return 1;
}
return 0;
}
void online()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef thuc
freopen("input.INP","r",stdin);
freopen("output.OUT","w",stdout);
#endif
}
const ll N=2e2+10;
ll n,L,pos[N],t[N],f[N][N][N][3];
ll tor(ll x,ll y)
{
if(y>x) return pos[y]-pos[x];
else return pos[y]+L-pos[x];
}
ll tol(ll x,ll y)
{
if(x>y) return pos[x]-pos[y];
else return pos[x]+L-pos[y];
}
int main()
{
online();
cin>>n>>L;
for(int i=1; i<=n; i++)
{
cin>>pos[i];
}
for(int i=1; i<=n; i++)
{
cin>>t[i];
}
memset(f,0x3f,sizeof f);
pos[n+1]=L;
f[n+1][0][0][0]=f[n+1][0][0][1]=0;
ll ans=0;
for(ll k=0; k<=n; k++)
{
for(int l=n+1; l>=1; l--)
{
for(int r=0; r<l; r++)
{
ll z=min(f[l][r][k][0]+tol(l,l-1),f[l][r][k][1]+tol(r,l-1));
if(z<=t[l-1]) minimize(f[l-1][r][k+1][0],z);
else minimize(f[l-1][r][k][0],z);
z=min(f[l][r][k][1]+tor(r,r+1),f[l][r][k][0]+tor(l,r+1));
if(z<=t[r+1]) minimize(f[l][r+1][k+1][1],z);
else minimize(f[l][r+1][k][1],z);
if(f[l][r][k][0]<=1e15) maximize(ans,k);
if(f[l][r][k][1]<=1e15) maximize(ans,k);
}
}
}
cout<<ans;
}
# | 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... |