Submission #295150

#TimeUsernameProblemLanguageResultExecution timeMemory
295150arayiRail (IOI14_rail)C++17
30 / 100
91 ms9080 KiB
#include <bits/stdc++.h>
#include "rail.h"
using namespace std;

int n, fr, sm, sc;
int a[1010][1010];
int getmn(int aa)
{
    int mn = INT_MAX, ret = aa;
    for (int i = 0; i < n; i++)
    {
        if(aa == i) continue;
        if(a[aa][i] < mn) mn = a[aa][i], ret = i;
    }
    return ret;
}
void findLocation(int N, int first, int location[], int stype[])
{
    n = N;
    fr = first;
    for (int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; ++j) a[i][j] = a[j][i] = getDistance(i, j);
    }
    stype[0] = 1, location[0] = first;
    if(n == 1) return;
    sm = getmn(0), sc = a[0][sm] + fr;
    for (int i = 1; i < n; i++)
    {
        int ss = getmn(i);
        if(ss == 0) stype[i] = 2, location[i] = fr + a[0][i];
        else if(ss == sm) stype[i] = 1, location[i] = sc - a[sm][i];
        else{
            if(a[0][sm] + a[sm][i] == a[0][i])
            {
                if(a[sm][ss] + a[ss][i] == a[sm][i]) stype[i] = 2, location[i] = sc - a[sm][ss] + a[ss][i];
                else stype[i] = 1, location[i] = sc - a[sm][i];
            }
            else
            {
                if(a[0][ss] + a[ss][i] == a[0][i]) stype[i] = 1, location[i] = fr + a[0][ss] - a[ss][i];
                else stype[i] = 2, location[i] = fr + a[0][i];
            }
        }
    }
    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...