Submission #436481

#TimeUsernameProblemLanguageResultExecution timeMemory
436481yuto1115Stations (IOI20_stations)C++17
76 / 100
1317 ms780 KiB
#include "stations.h"
#include "bits/stdc++.h"
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

vi label(int n, int k, vi u, vi v) {
    vvi G(n);
    rep(i, n - 1) {
        G[u[i]].pb(v[i]);
        G[v[i]].pb(u[i]);
    }
    int idx = 0;
    vi res(n);
    auto dfs = [&](auto &dfs, int now, int p, int d) -> void {
        if (d == 0) res[now] = idx;
        idx++;
        for (int nx : G[now]) {
            if (nx == p) continue;
            dfs(dfs, nx, now, d ^ 1);
        }
        if (d == 1) res[now] = idx;
        idx++;
    };
    dfs(dfs, 0, -1, 0);
    assert(idx == 2 * n);
    return res;
}

int find_next_station(int s, int t, vi c) {
    if (c[0] < s) {
        int pre = s;
        rrep(i, c.size()) {
            if (c[i] <= t and t < pre) return c[i];
            pre = c[i];
        }
        return pre;
    } else {
        int pre = s;
        rep(i, c.size()) {
            if (pre < t and t <= c[i]) return c[i];
            pre = c[i];
        }
        return pre;
    }
}
#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...