Submission #405254

#TimeUsernameProblemLanguageResultExecution timeMemory
405254blueRail (IOI14_rail)C++17
56 / 100
531 ms98464 KiB
#include "rail.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

//Subtask 3

/*
Let firstD be the leftmost station of type D to the ri


We can travel from station A to station B (A != B) in X switches if:

X = 0:
    pos(A) < pos(B) && type[A] == C && type[B] == D
    pos(B) < pos(A) && type[B] == C && type[A] == D

X = 1:
    type[A] == type[B]

X = 2:
    type[A] != type[B]

First, we can locate firstD[0] = X

                        0    X
                        (    )
    (    (      (      (
*/

int dist[5000][5000];

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

    if(n == 1) return;

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

    int order0[n];
    for(int i = 0; i < n; i++) order0[i] = i;

    sort(order0, order0 + n, [] (int x, int y)
    {
        return dist[0][x] < dist[0][y];
    });

    for(int j = 1; j < n; j++)
    {
        int i = order0[j];
        // cerr << "i = " << i << ' ' << dist[0][i] << '\n';

        vector<int> path;
        for(int k = 1; k < j; k++)
        {
            int i2 = order0[k];
            if(dist[0][i2] + dist[i2][i] == dist[0][i])
                path.push_back(i2);
        }

        if(path.size() == 0)
        {
            location[i] = location[0] + dist[0][i];
            stype[i] = 2;
        }
        else if(path.size() == 1)
        {
            location[i] = location[ path[0] ] - dist[ path[0] ][i];
            stype[i] = 1;
        }
        else if(path.size() == 2)
        {
            location[i] = location[ path[1] ] + dist[ path[1] ][i];
            stype[i] = 2;
        }
    }

    // cerr << "\n";
    // for(int i = 0; i < n; i++) cerr << stype[i] << ' ' << location[i] << '\n';
}




//Subtask 2
/*
int dist[100][100];

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

    if(n == 1)
        return;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            dist[i][j] = getDistance(i, j);

    int sort0[n];
    for(int i = 0; i < n; i++)
        sort0[i] = i;

    sort(sort0, sort0+n, [] (int x, int y)
    {
        return dist[0][x] < dist[0][y];
    });

    int firstRight = sort0[1];

    location[firstRight] = first + dist[0][firstRight];
    stype[firstRight] = 2;

    for(int i = 1; i < n; i++)
    {
        if(i == firstRight) continue;
        if(dist[0][i] == dist[0][firstRight] + dist[firstRight][i])
        {
            stype[i] = 1;
            location[i] = first + dist[0][firstRight] - dist[firstRight][i];
        }
        else
        {
            stype[i] = 2;
            location[i] = first + dist[0][i];
        }
    }

    cerr << "\n";
    for(int i = 0; i < n; i++) cerr << stype[i] << ' ' << location[i] << '\n';
}
*/


//Subtask 1
/*
void findLocation(int n, int first, int location[], int stype[])
{
    location[0] = first;
    stype[0] = 1;
    for(int i = 1; i < n; i++)
    {
        location[i] = first + getDistance(0, i);
        stype[i] = 2;
    }

    cerr << '\n';
    for(int i = 0; i < n; i++)
    {
        cerr << location[i] << ' ' << stype[i] << '\n';
    }
}

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