Submission #640483

#TimeUsernameProblemLanguageResultExecution timeMemory
640483piOOE도시들 (IOI15_towns)C++17
25 / 100
16 ms468 KiB
#include <bits/stdc++.h> #include "towns.h" using namespace std; int hubDistance(int n, int sub) { map<pair<int, int>, int> mp; auto mygetDistance = [&](int x, int y) { if (mp.count({x, y})) { return mp[{x, y}]; } else { return mp[{x, y}] = mp[{y, x}] = getDistance(x, y); } }; if (sub <= 2) { vector<int> dist(n); for (int i = 0; i < n; ++i) { dist[i] = mygetDistance(i, 0); } int v = max_element(dist.begin(), dist.end()) - dist.begin(); for (int i = 0; i < n; ++i) { dist[i] = mygetDistance(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] = mygetDistance(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] = mygetDistance(i, 0); } int v = max_element(dist.begin(), dist.end()) - dist.begin(); for (int i = 0; i < n; ++i) { dist[i] = mygetDistance(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] = mygetDistance(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) { if (i != u && i != v) { 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()); const int m = mega.size(); vector<int> adj(n), cnt(m); vector<vector<int>> kids(m); for (int i = 0; i < n; ++i) { if (i != u && i != v) { int e = dist[i] + dist2[i] - dist[u] >> 1; adj[i] = lower_bound(mega.begin(), mega.end(), dist[i] - e) - mega.begin(); assert(mega[adj[i]] == dist[i] - e); kids[adj[i]].push_back(i); ++cnt[adj[i]]; } } assert(*max_element(cnt.begin(), cnt.end()) < 3); for (int i = 0; i < m; ++i) { if (max(mega[i], dist[u] - mega[i]) == ans) { int L = 1, R = 1; for (int j = 0; j < i; ++j) { L += cnt[j]; } for (int j = i + 1; j < m; ++j) { R += cnt[j]; } if (max({L, R, cnt[i]}) <= n / 2) { return -ans; } } } return ans; } }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:20:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   20 |         int v = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:24:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   24 |         int u = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:31:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   31 |             int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:40:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   40 |         int v = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:44:55: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   44 |         int u = max_element(dist.begin(), dist.end()) - dist.begin();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:51:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   51 |             int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:57:44: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   57 |                 int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:63:32: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   63 |         const int m = mega.size();
      |                       ~~~~~~~~~^~
towns.cpp:68:44: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   68 |                 int e = dist[i] + dist2[i] - dist[u] >> 1;
towns.cpp:69:77: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   69 |                 adj[i] = lower_bound(mega.begin(), mega.end(), dist[i] - e) - mega.begin();
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
#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...