Submission #673068

#TimeUsernameProblemLanguageResultExecution timeMemory
6730681binRail (IOI14_rail)C++17
0 / 100
76 ms468 KiB
#include <bits/stdc++.h>
#include "rail.h"

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;

void findLocation(int n, int fi, int location[], int stype[]){
    vector<pair<int, int>> v;
    for(int i = 1; i < n; i++){
        int d = getDistance(0, i);
        v.emplace_back(d, i);
    }
    sort(all(v));
    location[0] = fi; stype[0] = 1;
    if(n == 1) return;
    
    auto [d0, x] = v[1];
    location[x] = fi + d0; stype[x] = 2;
    int l, r, dr, dl;
    l = 0, r = x, dl = d0 * 2, dr = d0;
    for(int i = 2; i < n; i++){
        auto&[d, x] = v[i];
        int d1 = getDistance(1, x);
        if(d0 + d1 == d){
            int xl = getDistance(l, x);
            if(d == dl + xl){
                location[x] = location[l] + dl;
                stype[x] = 2;
            }
            else{
                location[x] = fi + 2 * d0 - d;
                stype[x] = 1;
                l = x; dl = d;
            }
        }
        else{
            int xr = getDistance(r, x);
            if(d == dr + xr){
                location[x] = fi + dr - xr;
                stype[x] = 1;
            }
            else{
                location[x] = fi + d;
                stype[x] = 2;
                r = x; dr = d;
            }
        }
    }
    return;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...