Submission #1068393

#TimeUsernameProblemLanguageResultExecution timeMemory
1068393ArapakOvertaking (IOI23_overtaking)C++17
Compilation error
0 ms0 KiB
// Author: Kajetan Ramsza
#include "overtaking.h"
#include "bits/stdc++.h"
using namespace std;

#ifdef DEBUG
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;

auto& operator<<(auto &os, const pair<auto, auto> &p) {
    return os<<"("<<p.first<<", "<<p.second<<")";
}
auto& operator<<(auto &os, const auto &v) {
    os<<"{";
    for(auto it=begin(v);it!=end(v);++it) {
        if(it!=begin(v)) os<<", ";
        os<<(*it);
    }
    return os<<"}";
}

void dbg_out(auto... x) {
    ((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x);
#else
#define dbg(...)
#endif

struct BusState {
    ll arrival_time;
    int bus_index;
    ll next_arrival = -1;

    friend ostream& operator<<(ostream &os, const BusState &bs) {
        return os<<"{arr: "<<bs.arrival_time<<" ind: "<<bs.bus_index<<" next: "<<bs.next_arrival<<"}";
    }
};

int l, n, m;
vll t;
vi s, w;

vector<vector<BusState>> state;

ll get_expected_next_arrival(ll arrival, ll speed, int s_ind) {
    return arrival + speed * ll(s[s_ind+1] - s[s_ind]);
}

void calc_next_arrival(int index) {
    dbg(index);
    assert(0 <= index && index < m);
    auto &st = state[index];
    sort(all(st), [](const auto &a, const auto &b) {
        return a.arrival_time < b.arrival_time;
    });

    int prev = -1;
    rep(i,0,n) {
        ll expected_next_arrival = get_expected_next_arrival(st[i].arrival_time, w[st[i].bus_index], index); 
        if(i > 0 && st[i-1].arrival_time != st[i].arrival_time) {
            rep(j,prev+1,i)
                if(prev == -1 || st[j].next_arrival > st[prev].next_arrival)
                    prev = j;
        }

        if(prev == -1) 
            st[i].next_arrival = expected_next_arrival;
        else 
            st[i].next_arrival = max(expected_next_arrival, st[prev].next_arrival);
    }

    sort(all(state[index]), [](const auto &a, const auto &b) {
        return tie(a.arrival_time, a.next_arrival) < tie(b.arrival_time, b.next_arrival);
    });
}

void preprocess() {
    state.assign(m, vector<BusState>(n));
    rep(i,0,n) state[0][i] = {t[i], i, -1};
    rep(s_ind,0,m-1) {
        calc_next_arrival(s_ind);
        rep(i,0,n) 
            state[s_ind+1][i] = {state[s_ind][i].next_arrival, state[s_ind][i].bus_index, -1};
    }
}

int X;

void init(int L, int N, vll T,  vi W, int _X, int M, vi S) {
    l = L;
    n = N;
    t = T;
    w = W;
    X = _X;
    m = M;
    s = S;
    dbg(l, n, m);
    preprocess();
    rep(i,0,m) dbg(state[i]);
}

ll find_worst_next_arrival(int s_ind, ll arrival) {
    int b = 0, e = n;
    while(b < e) {
        int mid = (b+e) / 2;
        if(state[s_ind][mid].arrival_time < arrival)
            b = mid + 1;
        else e = mid;
    }
    return b == 0 ? -1 : state[s_ind][b-1].next_arrival;
}

ll arrival_time(ll Y) {
    dbg(X, Y);
    rep(s_ind,0,m-1) {
        ll expected_next_arrival = get_expected_next_arrival(Y, X, s_ind);
        ll worst_next_arrival = find_worst_next_arrival(s_ind, Y);
        dbg(s_ind, expected_next_arrival, worst_next_arrival);
        Y = max(expected_next_arrival, worst_next_arrival);
    }
    return Y;
}

Compilation message (stderr)

overtaking.cpp:36:5: error: 'll' does not name a type
   36 |     ll arrival_time;
      |     ^~
overtaking.cpp:38:5: error: 'll' does not name a type
   38 |     ll next_arrival = -1;
      |     ^~
overtaking.cpp: In function 'std::ostream& operator<<(std::ostream&, const BusState&)':
overtaking.cpp:41:33: error: 'const struct BusState' has no member named 'arrival_time'
   41 |         return os<<"{arr: "<<bs.arrival_time<<" ind: "<<bs.bus_index<<" next: "<<bs.next_arrival<<"}";
      |                                 ^~~~~~~~~~~~
overtaking.cpp:41:85: error: 'const struct BusState' has no member named 'next_arrival'
   41 |         return os<<"{arr: "<<bs.arrival_time<<" ind: "<<bs.bus_index<<" next: "<<bs.next_arrival<<"}";
      |                                                                                     ^~~~~~~~~~~~
overtaking.cpp: At global scope:
overtaking.cpp:46:1: error: 'vll' does not name a type
   46 | vll t;
      | ^~~
overtaking.cpp:47:1: error: 'vi' does not name a type
   47 | vi s, w;
      | ^~
overtaking.cpp:51:1: error: 'll' does not name a type; did you mean 'l'?
   51 | ll get_expected_next_arrival(ll arrival, ll speed, int s_ind) {
      | ^~
      | l
overtaking.cpp: In function 'void calc_next_arrival(int)':
overtaking.cpp:59:10: error: 'all' was not declared in this scope; did you mean 'std::filesystem::perms::all'?
   59 |     sort(all(st), [](const auto &a, const auto &b) {
      |          ^~~
      |          std::filesystem::perms::all
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from overtaking.cpp:3:
/usr/include/c++/10/bits/fs_fwd.h:148:7: note: 'std::filesystem::perms::all' declared here
  148 |       all  =  0777,
      |       ^~~
overtaking.cpp:64:9: error: 'i' was not declared in this scope
   64 |     rep(i,0,n) {
      |         ^
overtaking.cpp:64:5: error: 'rep' was not declared in this scope
   64 |     rep(i,0,n) {
      |     ^~~
overtaking.cpp:63:9: warning: unused variable 'prev' [-Wunused-variable]
   63 |     int prev = -1;
      |         ^~~~
overtaking.cpp: In function 'void preprocess()':
overtaking.cpp:85:9: error: 'i' was not declared in this scope
   85 |     rep(i,0,n) state[0][i] = {t[i], i, -1};
      |         ^
overtaking.cpp:85:5: error: 'rep' was not declared in this scope
   85 |     rep(i,0,n) state[0][i] = {t[i], i, -1};
      |     ^~~
overtaking.cpp:86:9: error: 's_ind' was not declared in this scope
   86 |     rep(s_ind,0,m-1) {
      |         ^~~~~
overtaking.cpp: At global scope:
overtaking.cpp:95:25: error: 'vll' has not been declared
   95 | void init(int L, int N, vll T,  vi W, int _X, int M, vi S) {
      |                         ^~~
overtaking.cpp:95:33: error: 'vi' has not been declared
   95 | void init(int L, int N, vll T,  vi W, int _X, int M, vi S) {
      |                                 ^~
overtaking.cpp:95:54: error: 'vi' has not been declared
   95 | void init(int L, int N, vll T,  vi W, int _X, int M, vi S) {
      |                                                      ^~
overtaking.cpp: In function 'void init(int, int, int, int, int, int, int)':
overtaking.cpp:98:5: error: 't' was not declared in this scope
   98 |     t = T;
      |     ^
overtaking.cpp:99:5: error: 'w' was not declared in this scope
   99 |     w = W;
      |     ^
overtaking.cpp:102:5: error: 's' was not declared in this scope
  102 |     s = S;
      |     ^
overtaking.cpp:105:9: error: 'i' was not declared in this scope
  105 |     rep(i,0,m) dbg(state[i]);
      |         ^
overtaking.cpp:105:5: error: 'rep' was not declared in this scope
  105 |     rep(i,0,m) dbg(state[i]);
      |     ^~~
overtaking.cpp: At global scope:
overtaking.cpp:108:1: error: 'll' does not name a type; did you mean 'l'?
  108 | ll find_worst_next_arrival(int s_ind, ll arrival) {
      | ^~
      | l
overtaking.cpp:119:1: error: 'll' does not name a type; did you mean 'l'?
  119 | ll arrival_time(ll Y) {
      | ^~
      | l