Submission #640458

#TimeUsernameProblemLanguageResultExecution timeMemory
640458piOOETowns (IOI15_towns)C++17
25 / 100
21 ms884 KiB
#include <bits/stdc++.h>
#include "towns.h"

using namespace std;

int hubDistance(int n, int sub) {
    if (sub <= 2) {
        vector<int> dist(n);
        for (int i = 0; i < n; ++i) {
            dist[i] = getDistance(i, 0);
        }
        int v = max_element(dist.begin(), dist.end()) - dist.begin();
        for (int i = 0; i < n; ++i) {
            dist[i] = getDistance(i, v);
        }
        int u = max_element(dist.begin(), dist.end()) - dist.begin();
        vector<int> dist2(n);
        for (int i = 0; i < n; ++i) {
            dist2[i] = getDistance(i, u);
        }
        int ans = numeric_limits<int>::max();
        for (int i = 0; i < n; ++i) {
            int e = dist[i] + dist2[i] - dist[u] >> 1;
            ans = min(ans, max(dist[i] - e, dist2[i] - e));
        }
        return ans;
    } else {
        vector<int> dist(n);
        for (int i = 0; i < n; ++i) {
            dist[i] = getDistance(i, 0);
        }
        int v = max_element(dist.begin(), dist.end()) - dist.begin();
        for (int i = 0; i < n; ++i) {
            dist[i] = getDistance(i, v);
        }
        int u = max_element(dist.begin(), dist.end()) - dist.begin();
        vector<int> dist2(n);
        for (int i = 0; i < n; ++i) {
            dist2[i] = getDistance(i, u);
        }
        int ans = numeric_limits<int>::max();
        for (int i = 0; i < n; ++i) {
            int e = dist[i] + dist2[i] - dist[u] >> 1;
            ans = min(ans, max(dist[i] - e, dist2[i] - e));
        }
        vector<int> mega;
        for (int i = 0; i < n; ++i) {
            int e = dist[i] + dist2[i] - dist[u] >> 1;
            mega.push_back(dist[i] - e);
        }
        sort(mega.begin(), mega.end());
        mega.resize(unique(mega.begin(), mega.end()) - mega.begin());
        for (int i = 0; i < n; ++i) {
            int e = dist[i] + dist2[i] - dist[u] >> 1;
            int mx = max(dist[i] - e, dist2[i] - e);
            e = dist[i] - e;
            int pos = lower_bound(mega.begin(), mega.end(), e) - mega.begin();
            if ((pos + 1) * 2 <= n || (n - pos) * 2 <= n) {
                return -ans;
            }
        }
        return ans;
    }
}

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:12:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   12 |         int v = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:16:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   16 |         int u = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:23:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   23 |             int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:32:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   32 |         int v = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:36:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   36 |         int u = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:43:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   43 |             int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:48:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   48 |             int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:54:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   54 |             int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:57:64: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   57 |             int pos = lower_bound(mega.begin(), mega.end(), e) - mega.begin();
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:55:17: warning: unused variable 'mx' [-Wunused-variable]
   55 |             int mx = max(dist[i] - e, dist2[i] - e);
      |                 ^~
#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...