Submission #1057822

#TimeUsernameProblemLanguageResultExecution timeMemory
1057822thieunguyenhuyRail (IOI14_rail)C++17
30 / 100
67 ms97620 KiB
#ifndef hwe
    #include "rail.h"
#endif

#include <bits/stdc++.h>
using namespace std;

#define popcount(n) (__builtin_popcountll((n)))
#define clz(n) (__builtin_clzll((n)))
#define ctz(n) (__builtin_ctzll((n)))
#define lg(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))

#define Int __int128
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;

template <class T1, class T2>
bool maximize(T1 &x, T2 y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template <class T>
void remove_duplicate(vector<T> &ve) {
    sort (ve.begin(), ve.end());
    ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T> T random(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}
template <class T> T random(T r) {
    return rng() % r;
}

const int N = 5000 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;

int dist[N][N];

#ifdef hwe
int getDistance(int i, int j) {
    return 0;
}
#endif

void findLocation(int n, int first, int location[], int stype[]) {
    location[0] = first, stype[0] = 1;
    for (int i = 1; i < n; ++i) dist[0][i] = getDistance(0, i);

    vector<int> order(n - 1); iota(order.begin(), order.end(), 1);
    sort (order.begin(), order.end(), [&](int x, int y) {
        return dist[0][x] < dist[0][y];
    });

    location[order[0]] = location[0] + dist[0][order[0]], stype[order[0]] = 2;
    int L = 0, R = order[0];
    vector<int> C = {L}, D = {R};
    
    auto check_case1 = [&](int k) {
        int pos = location[L] + dist[k][L], ma = -inf;
        if (pos >= location[R]) return false;
        for (auto x : C) {
            if (location[x] < pos) maximize(ma, location[x]);
        }
        assert(ma != -inf);
        return dist[k][R] == pos - ma + location[R] - ma;
    };

    auto check_case2 = [&](int k) {
        int pos = location[L] + dist[k][L], ma = -inf;
        if (pos <= location[R]) return false;
        for (auto x : C) {
            if (location[x] < location[R]) maximize(ma, location[x]);
        }
        assert(ma != -inf);
        return dist[k][R] == pos - ma + location[R] - ma;
    };

    for (int _ = 1; _ < order.size(); ++_) {
        int k = order[_]; dist[k][L] = getDistance(k, L), dist[k][R] = getDistance(k, R);
        if (check_case1(k) || check_case2(k)) location[k] = location[L] + dist[k][L], stype[k] = 2;
        else location[k] = location[R] - dist[k][R], stype[k] = 1;

        if (stype[k] == 1) {
            C.emplace_back(k);
            if (location[k] < location[L]) L = k;
        }
        else {
            D.emplace_back(k);
            if (location[k] > location[R]) R = k;
        }
    }
}

#ifdef hwe
signed main() {


    cerr << '\n'; return 0;
}
#endif

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:111:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for (int _ = 1; _ < order.size(); ++_) {
      |                     ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...