Submission #745533

# Submission time Handle Problem Language Result Execution time Memory
745533 2023-05-20T10:04:18 Z Pacybwoah Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
1 ms 468 KB
#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;
    assert(n==2);
    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];
    vector<vector<vector<vector<ll>>>> dp(n+1,vector<vector<vector<ll>>>(n+1,vector<vector<ll>>(n+1,vector<ll>(2,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=j+1;k<=n;k++){
                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
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -