Submission #959785

# Submission time Handle Problem Language Result Execution time Memory
959785 2024-04-09T05:25:58 Z ReLice Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18+5;
const ll mod=1e9+7;
const ld eps=1e-9;
const ll N=2e2+5;
const ll M=1e6+5;
ll dp[N][N][N];
ll x[N],t[N];
ll n,l;
ll dis(ll i,ll j){
    return min(abs(x[i]-x[j]),min(x[i],x[j])+l-max(x[i],x[j]));
}
void solve(){
    ll i,j;
    cin>>n>>l;
    for(i=1;i<=n;i++) cin>>x[i];
    for(i=1;i<=n;i++) cin>>t[i];
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            for(ll q=0;q<=n;q++)dp[i][j][q]=inf;
        }
    }
    if(dis(0,1)<=t[1]) dp[1][n][1]=dis(0,1);
    else dp[1][n][0]=dis(0,1);
    if(dis(0,n)<=t[n]) dp[n][1][1]=dis(0,n);
    else dp[n][1][0]=dis(0,n);
    ll ans=0;
    for(ll q=0;q<=n;q++){
        for(i=1;i<=n;i++){
            if(dp[i][i][q]<inf)chmax(ans,q);
            if(q==n)continue;
            for(j=n;j>i;j--){
                if(dp[i][j][q]>=inf)continue;
                chmax(ans,q);
                //cout<<dp[i][j][q]<<endl<<i<<' '<<j<<' '<<q<<endl;
                if(dis(i,j)<=t[j]-dp[i][j][q]) chmin(dp[j][i+1][q+1],dp[i][j][q]+dis(i,j));
                else chmin(dp[j][i+1][q],dp[i][j][q]+dis(i,j));
                if(dis(i,i+1)<=t[i+1]-dp[i][j][q]) chmin(dp[i+1][j][q+1],dp[i][j][q]+dis(i,i+1));
                else chmin(dp[i+1][j][q],dp[i][j][q]+dis(i,i+1));
            }
            for(j=1;j<i;j++){
                if(dp[i][j][q]>=inf)continue;
                chmax(ans,q);
                //cout<<dp[i][j][q]<<endl<<i<<' '<<j<<' '<<q<<endl;
                if(dis(i,j)<=t[j]-dp[i][j][q]) chmin(dp[j][i-1][q+1],dp[i][j][q]+dis(i,j));
                else chmin(dp[j][i-1][q],dp[i][j][q]+dis(i,j));
                if(dis(i,i-1)<=t[i-1]-dp[i][j][q]) chmin(dp[i-1][j][q+1],dp[i][j][q]+dis(i,i-1));
                else chmin(dp[i-1][j][q],dp[i][j][q]+dis(i,i-1));
            }
        }
    }
    cout<<ans<<endl;
}
signed main(){
	start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*




*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -