Submission #1240149

#TimeUsernameProblemLanguageResultExecution timeMemory
1240149nasjesCollecting Stamps 3 (JOI20_ho_t3)C++20
0 / 100
118 ms292244 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 3*1e2+7;
//const ll mod = 1e9 + 7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>

ll n, l;
ll dp[dim][dim][dim][3]; //l r ans 2
ll x[dim], t[dim];

pll can(ll cur, ll st, ll fn, ll tp){
    ll dist=0, add=0;
    if(fn>n)return{ 0, inf};
    if(tp==1){// це те що ми йдемо в тому ж напрямку
        dist=abs(x[st]-x[fn]);
        if(cur+dist<=t[fn])add=1;
        return {add, cur+dist};
    }
    if(tp==2){
        dist=l-abs(x[st]-x[fn]);//+-1
        if(cur+dist<=t[fn])add=1;
        return {add, cur+dist};
    }

}
int main() {
    ll  u0, v0;
    string s1;
    cin>>n>>l;
    for(int i=0; i<=200; i++){
        for(int j=0; j<=200; j++){
            for(int k=0; k<=200; k++){
                dp[i][j][k][1]=inf;
                dp[i][j][k][2]=inf;
            }
        }
    }
    for(int i=1; i<=n; i++) {
        cin>>x[i];
    }
    for(int i=1; i<=n; i++) {
        cin>>t[i];
    }
    ll ans=0;
    dp[0][0][0][1]=0;
    dp[0][0][0][2]=0;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            if(i+j>=n)continue;
            for(int have=0; have<=i+j; have++){
                if(dp[i][j][have][1]<inf)ans=max<ll>(ans, have);
                if(dp[i][j][have][2]<inf)ans=max<ll>(ans, have);
                // i -> i+1
                pll op1=can(dp[i][j][have][1], i, i+1, 1);
                pll op2=can(dp[i][j][have][1], i, i+1, 2);
                ll add=0; ll tm=0;
                add=op1.fi; tm=op1.se;
                dp[i+1][j][have+add][1]=min(dp[i+1][j][have+add][1], tm);
                add=op2.fi; tm=op2.se;
                dp[i+1][j][have+add][1]=min(dp[i+1][j][have+add][1], tm);
                // i --- j+1
                op1=can(dp[i][j][have][1], i, j+1, 1);
                op2=can(dp[i][j][have][1], i, j+1, 2);
                add=op1.fi; tm=op1.se;
                dp[i][j+1][have+add][2]=min<ll>(dp[i][j+1][have+add][2], tm);
                add=op2.fi; tm=op2.se;
                dp[i][j+1][have+add][2]=min<ll>(dp[i][j+1][have+add][2], tm);

                // j -- j+1
                op1=can(dp[i][j][have][2], j, j+1, 1);
                op2=can(dp[i][j][have][2], j, j+1, 2);
                add=op1.fi; tm=op1.se;
                dp[i][j+1][have+add][2]=min<ll>(dp[i][j+1][have+add][2], tm);
                add=op2.fi; tm=op2.se;
                dp[i][j+1][have+add][2]=min(dp[i][j+1][have+add][2], tm);

                // j - i+1
                op1=can(dp[i][j][have][2], j, i+1, 1);
                op2=can(dp[i][j][have][2], j, i+1, 2);
                add=op1.fi; tm=op1.se;
                dp[i+1][j][have+add][1]=min(dp[i+1][j][have+add][1], tm);
                add=op2.fi; tm=op2.se;
                dp[i+1][j][have+add][1]=min(dp[i+1][j][have+add][1], tm);
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Compilation message (stderr)

ho_t3.cpp: In function 'pll can(ll, ll, ll, ll)':
ho_t3.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
   46 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...