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 cin(vec) for(auto& i : vec) cin >> i
#define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define loop(i,a,b) for (int i = a; i < b; i++)
#define F first
#define S second
#define pb(n) push_back(n)
#define pf(n) push_front(n)
#define dci(d) fixed<<setprecision(d)
#define sp ' '
#define el '\n'
#define all(v) v.begin(),v.end()
#define int long long
int dx[8]= {0,0,1,-1,-1,1,1,-1};
int dy[8]= {-1,1,0,0,-1,1,-1,1};
int const N=1e4+5,M=1e3+1,Mod=1e9+7;
int a[202],t[202],n,len;
int dp[201][201][201][2];
int dist(int t1,int t2,int i,int j){
if(t2==0){
if(t1==0)
return (a[i]-a[i-1]);
else
return (len-a[j]+a[i-1]);
}
else{
if(t1==1)
return (a[j+1]-a[j]);
else
return (a[i]+len-a[j+1]);
}
}
void testcase(int h){
cin>>n>>len;
int mx=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>t[i];
for(int i=0;i<=n+1;i++){
for(int j=n+1;j>=i;j--){
for(int t=0;t<=1;t++){
for(int cnt=1;cnt<=n+1;cnt++){
dp[i][j][cnt][t]=1e18;
}
}
}
}
a[n+1]=len;
for(int i=1;i<=n;i++){
for(int j=n;j>=i;j--){
for(int cnt=0;cnt<=n;cnt++){
for(int tp=0;tp<=1;tp++){
dp[i][j][cnt][tp]=min(dp[i-1][j][cnt][0]+dist(tp,0,i,j)
,dp[i][j+1][cnt][1]+dist(tp,1,i,j));
if(cnt){
int a=min(dp[i][j+1][cnt-1][1]+dist(tp,1,i,j)
,dp[i-1][j][cnt-1][0]+dist(tp,0,i,j));
if((!tp&&a<=t[i])||(tp&&a<=t[j])){
dp[i][j][cnt][tp]=min(dp[i][j][cnt][tp],a);
mx=max(mx,cnt);
}
}
}
}
}
}
cout<<mx;
}
int32_t main()
{
// fast
testcase(1);
// int tc;cin>>tc;for(int i=1;i<=tc;i++)testcase(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... |