Submission #1063874

#TimeUsernameProblemLanguageResultExecution timeMemory
1063874ProtonDecay314Overtaking (IOI23_overtaking)C++17
65 / 100
3567 ms26204 KiB
#include "overtaking.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vpi> vvpi;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef short int si;
typedef vector<si> vsi;
typedef vector<vsi> vvsi;
#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define L(varll, mn, mx) for(ll varll = (mn); varll < (mx); varll++)
#define LR(varll, mx, mn) for(ll varll = (mx); varll > (mn); varll--)
#define LI(vari, mn, mx) for(int vari = (mn); vari < (mx); vari++)
#define LIR(vari, mx, mn) for(int vari = (mx); vari > (mn); vari--)
#define INPV(varvec) for(auto& varveci : (varvec)) cin >> varveci
#define fi first
#define se second
#define pb push_back
#define INF(type) numeric_limits<type>::max()
#define NINF(type) numeric_limits<type>::min()
#define TCASES int t; cin >> t; while(t--)

struct bus {
    ll v;
    ll s;
    ll e;
};

typedef vector<bus> vbu;

typedef vector<vbu> vvbu;


ll x;
vi s;
ll n;
ll m;

vbu cur_buses;
vvbu bus_configs;

void init(int L, int N, vll T, vi W, int X, int M, vi S)
{
    // ! No need to clear variables! This procedure is only called once :)) 

    LI(i, 0, N) {
        if(W[i] > X) {
            cur_buses.pb({W[i] - X, T[i], T[i]});
        }
    }

    n = cur_buses.size();
    x = X;
    s = S;
    m = M;

    LI(i, 0, M) {
        vbu bus_configs_r;
        bus_configs.pb(bus_configs_r);
    }

    // Learning: vector assignment in C++
    // implicitly calls the copy constructor
    sort(cur_buses.begin(), cur_buses.end(), [](bus& b1, bus& b2) {return b1.e < b2.e || (b1.e == b2.e && b1.v < b2.v);});

    bus_configs[0] = cur_buses;

    L(i, 1, M) {
        // For each sorting station, simulate the advance of the buses

        sort(cur_buses.begin(), cur_buses.end(), [](bus& b1, bus& b2) {return b1.e < b2.e || (b1.e == b2.e && b1.v < b2.v);});
        L(j, 0, n) cur_buses[j].s = cur_buses[j].e;

        ll max_t = 0ll;

        ll ds = S[i] - S[i - 1ll];

        L(j, 0, n) {
            max_t = max(max_t, cur_buses[j].s + cur_buses[j].v * ds);
            cur_buses[j].e = max_t;
            // cout << "( " << cur_buses[j].s << ", " << cur_buses[j].e << " ), ";
        }
        // cout << "\n";

        bus_configs[i] = cur_buses;
    }

    return;
}

ll arrival_time(ll Y)
{
    // for each bus whose arrival time is less than the current, get the maximum time
    ll cur_pos = Y;

    L(i, 1ll, m) {
        ll ds = s[i] - s[i - 1ll];
        ll max_t = cur_pos;

        ll l = -1ll, r = n;
        while(r - l > 1) {
            ll m = (l + r) >> 1ll;

            if(bus_configs[i][m].s < cur_pos) l = m;
            else r = m;
        }

        if(l >= 0ll) {
            max_t = max(max_t, bus_configs[i][l].e);
        }

        cur_pos = max_t;
        // cout << cur_pos << " ";
    }

    // cout << "\n";

    return cur_pos + x * (s[m - 1ll] - s[0ll]);
}

Compilation message (stderr)

overtaking.cpp: In function 'll arrival_time(ll)':
overtaking.cpp:107:12: warning: unused variable 'ds' [-Wunused-variable]
  107 |         ll ds = s[i] - s[i - 1ll];
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...