Submission #586694

#TimeUsernameProblemLanguageResultExecution timeMemory
586694InternetPerson10Towns (IOI15_towns)C++17
25 / 100
19 ms860 KiB
#include "towns.h"
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

map<pair<int, int>, int> distances;

int getDist(int i, int j) {
    if(i == j) return 0;
    if(i > j) swap(i, j);
    if(distances.count({i, j})) {
        return distances[make_pair(i, j)];
    }
    return distances[make_pair(i, j)] = getDistance(i, j);
}

vector<int> dists;

int hubDistance(int N, int sub) {
    ll ans = 2e10;
    distances.clear();
    dists.clear();
    dists.resize(N);
    int ma = -1, best = -1;
    for(int i = 0; i < N; i++) {
        dists[i] = getDist(0, i);
        if(ma < dists[i]) {
            ma = dists[i];
            best = i;
        }
    }
    int x = best;
    ma = -1, best = -1;
    for(int i = 0; i < N; i++) {
        dists[i] = getDist(x, i);
        if(ma < dists[i]) {
            ma = dists[i];
            best = i;
        }
    }
    int y = best;
    int c = ma;
    for(int i = 0; i < N; i++) {
        if(i == x || i == y) continue;
        int a = getDist(x, i);
        int b = getDist(y, i);
        ans = min(ans, max((ll)a + c - b, (ll)b + c - a));
    }
    return ans/2;
}

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:50:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   50 |     return ans/2;
      |            ~~~^~
towns.cpp:20:28: warning: unused parameter 'sub' [-Wunused-parameter]
   20 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~
#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...