Submission #778714

#TimeUsernameProblemLanguageResultExecution timeMemory
778714danikoynovTowns (IOI15_towns)C++14
35 / 100
13 ms980 KiB
#include "towns.h"
#include <bits/stdc++.h>

using namespace std;
const int maxn = 120;
int dist[maxn];

int hubDistance(int N, int sub)
{
    int v = 0, u = -1, best = 0;
    for (int i = 1; i < N; i ++)
    {
        int d = getDistance(i, 0);
        if (u == -1 || d > best)
        {
            best = d;
            u = i;
        }
    }
    dist[0] = best;
    for (int i = 1; i < N; i ++)
    {
        if (i != u)
        {
            int d = getDistance(i, u);
            dist[i] = d;
            if (d > best)
            {
                best = d;
                v = i;
            }
        }
    }
    if (sub == 4)
    {
        map < int, int > marked;
        int ans = 1e9;
        for (int i = 0; i < N; i ++)
        {
            if (i == v || i == u)
                continue;
            int df = getDistance(v, i), tf = dist[i];
            int diff = abs(df - tf);
            int lf = (best - diff) / 2 + diff, rf = (best - diff) / 2;
            if (df < tf)
                swap(lf, rf);
            marked[lf] ++;
            ans = min(ans, (best - diff) / 2 + diff);
        }
        int from_left = 1;
        for (auto it : marked)
        {
            int from_right = N - from_left - it.second;
            if (max(it.first, best - it.first) == ans)
            {
                if (max(from_right, max(it.second, from_left)) <= N / 2)
                    return +ans;
            }
            from_left += it.second;
        }
        return -ans;
    }
    else
    {

        int ans = 1e9;
        for (int i = 0; i < N; i ++)
        {
            if (i == v || i == u)
                continue;
            int df = getDistance(v, i), tf = dist[i];
            int diff = abs(df - tf);
            ans = min(ans, (best - diff) / 2 + diff);
        }

        return ans;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...