Submission #168619

#TimeUsernameProblemLanguageResultExecution timeMemory
168619dolphingarlicRail (IOI14_rail)C++14
30 / 100
84 ms632 KiB
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;

int A = -1, B = -1, C = -1, D = -1;
int from_A[5001], from_B[5001];

bool left_cmp(int X, int Y) { return from_B[X] < from_B[Y]; }
bool right_cmp(int X, int Y) { return from_A[X] < from_A[Y]; }

void findLocation(int N, int first, int location[], int stype[]) {
    A = 0;
    location[A] = first;
    stype[A] = 1;

    int min_from_A = INT_MAX;
    for (int i = 1; i < N; i++) {
        from_A[i] = getDistance(A, i);
        if (from_A[i] < min_from_A) {
            min_from_A = from_A[i];
            B = i;
        }
    }

    from_B[A] = from_A[B];
    location[B] = first + from_A[B];
    stype[B] = 2;

    vector<int> left, right;

    for (int i = 1; i < N; i++) {
        if (i == B) continue;
        from_B[i] = getDistance(B, i);
        if (from_A[i] > from_B[i]) left.push_back(i);
        else right.push_back(i);
    }

    sort(left.begin(), left.end(), left_cmp);
    sort(right.begin(), right.end(), right_cmp);

    for (int i : left) {
        if (C == -1) {
            C = i;
            location[C] = location[B] - from_B[C];
            stype[C] = 1;
        } else {
            int from_C = getDistance(C, i);
            if (from_B[i] - from_C == from_B[C]) {
                location[i] = location[C] + from_C;
                stype[i] = 2;
            } else {
                C = i;
                location[C] = location[B] - from_B[C];
                stype[C] = 1;
            }
        }
    }

    for (int i : right) {
        if (D == -1) {
            D = i;
            location[D] = location[A] + from_A[D];
            stype[D] = 2;
        } else {
            int from_D = getDistance(D, i);
            if (from_A[i] - from_D == from_A[D]) {
                location[i] = location[D] - from_D;
                stype[i] = 1;
            } else {
                D = i;
                location[D] = location[A] + from_A[D];
                stype[D] = 2;
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...