Submission #1102124

#TimeUsernameProblemLanguageResultExecution timeMemory
1102124alexander707070Rail (IOI14_rail)C++14
56 / 100
95 ms840 KiB
#include<bits/stdc++.h>
#include "rail.h"

#define MAXN 1000007
using namespace std;

int n,pos;
pair<int,int> block[MAXN];
pair<int,int> dist[5007];
int last;

vector<int> clos;
int sum[MAXN];

void findLocation(int N, int first, int location[], int stype[]){
    n=N;
    block[first]={0,0};

    location[0]=first;
    stype[0]=1;

    for(int i=1;i<n;i++){
        dist[i].first=getDistance(0,i);
        dist[i].second=i;
    }

    sort(dist+1,dist+n);

    last=1;
    location[dist[1].second]=first+dist[1].first;
    stype[dist[1].second]=2;
    clos.push_back(1);

    for(int i=2;i<n;i++){

        bool ok=true;
        for(int f:clos){
            if(dist[f].first+getDistance(dist[f].second,dist[i].second)==dist[i].first){
                ok=false; break;
            }
        }

        if(ok){
            clos.push_back(i);
            last=i;

            stype[dist[i].second]=2;
            location[dist[i].second]=first+dist[i].first;
        }
    }

    int special=dist[last].second;
    int fin=location[special];

    for(int i=0;i<n;i++){
        dist[i].first=getDistance(special,i);
        dist[i].second=i;
    }

    sort(dist,dist+n);

    last=1;
    location[dist[1].second]=fin-dist[1].first;
    stype[dist[1].second]=1;
    clos={1};

    for(int i=2;i<n;i++){

        bool ok=true;
        for(int f:clos){
            //if(dist[i].first-dist[f].first<=sum[f])continue;

            if(dist[f].first+getDistance(dist[f].second,dist[i].second)==dist[i].first){
                location[dist[i].second]=fin-dist[f].first+(dist[i].first-dist[f].first);
                stype[dist[i].second]=2;
                sum[f]=(dist[i].first-dist[f].first);

                ok=false;
                break;
            }
        }

        if(ok){
            last=i;

            stype[dist[i].second]=1;
            location[dist[i].second]=fin-dist[i].first;
            clos.push_back(i);
        }
    }

    return;
}

/*
3
8
1 0
2 2
1 3
2 5
2 6
1 7
1 8
2 10


*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...