Submission #553736

#TimeUsernameProblemLanguageResultExecution timeMemory
553736keta_tsimakuridzeTowns (IOI15_towns)C++14
35 / 100
23 ms880 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second const int N = 505; ll d[2][N], dist[N][N]; map<int,int> cnt; map<int,vector<int> > c; int hubDistance(int n, int sub) { int U = 0, V = 0; for(int i = 0; i < n; i++) { d[0][i] = getDistance(0, i); if(d[0][i] >= d[0][U]) U = i; } for(int i = 0; i < n; i++) { d[1][i] = getDistance(U, i); if(d[1][i] >= d[1][V]) V = i; } vector<ll> v; ll Distance = 0; cnt.clear(); vector<int> f(n + 5); for(int i = 0; i < n; i++) { ll D = (d[1][i] + d[0][i] - d[0][U]) / 2; D = d[1][i] - D; v.push_back(D); cnt[D]++; f[i] = D; if(i == V) Distance = D; } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); ll R = 1e18, cnR = 0; for(int i = 0; i < v.size(); i++) { if(v[i] > Distance) break; ll x = (d[1][V] + d[0][V] - d[0][U]) / 2 + Distance - v[i]; R = min(R, max(v[i], x)); } for(int i = 0; i < v.size(); i++) { if(v[i] > Distance) break; ll x = (d[1][V] + d[0][V] - d[0][U]) / 2 + Distance - v[i]; if(R == max(v[i], x)) { if(cnR <= n / 2 && cnt[v[i]] <= n / 2 && n - cnR - cnt[v[i]] <= n / 2) return R; if(cnR <= n / 2 && n - cnR - cnt[v[i]] <= n / 2) { vector<pii> cur; for(int j = 0; j < n; j++) { cur.push_back({j, 1}); } vector<pii> save; while(cur.size() >= 2) { vector<pii> cn; for(int j = 0; j + 1 < cur.size(); j += 2) { int D = getDistance(cur[j].f, cur[j + 1].f); if(D != d[1][cur[j].f] + d[1][cur[j + 1].f] - 2 * f[cur[j].f] && f[cur[j].f] == f[cur[j + 1].f]) { cn.push_back({cur[j + 1].f, cur[j + 1].s + cur[j].s}); } else save.push_back(cur[j]), save.push_back(cur[j + 1]); } if(cur.size() % 2) cn.push_back(cur.back()); cur = cn; } if(!cur.size() || f[cur[0].f] != v[i]) return R; int sz = cur[0].s; for(int j = 0; j < save.size(); j++) { int D = getDistance(cur[0].f, save[j].f); if(D != d[1][cur[0].f] + d[1][save[j].f] - 2 * v[i] && f[cur[0].f] == f[save[j].f]) sz += save[j].s; } if(sz <= n / 2) return R; } } cnR += cnt[v[i]]; } return -R; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:31:7: warning: conversion from 'long long int' to 'std::map<int, int>::key_type' {aka 'int'} may change value [-Wconversion]
   31 |   cnt[D]++;
      |       ^
towns.cpp:32:10: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   32 |   f[i] = D;
      |          ^
towns.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i = 0; i < v.size(); i++) {
      |                 ~~^~~~~~~~~~
towns.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i = 0; i < v.size(); i++) {
      |                 ~~^~~~~~~~~~
towns.cpp:47:31: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::map<int, int>::key_type' {aka 'int'} may change value [-Wconversion]
   47 |    if(cnR <= n / 2 && cnt[v[i]] <= n / 2 && n - cnR - cnt[v[i]] <= n / 2) return R;
      |                               ^
towns.cpp:47:63: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::map<int, int>::key_type' {aka 'int'} may change value [-Wconversion]
   47 |    if(cnR <= n / 2 && cnt[v[i]] <= n / 2 && n - cnR - cnt[v[i]] <= n / 2) return R;
      |                                                               ^
towns.cpp:47:82: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   47 |    if(cnR <= n / 2 && cnt[v[i]] <= n / 2 && n - cnR - cnt[v[i]] <= n / 2) return R;
      |                                                                                  ^
towns.cpp:49:41: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::map<int, int>::key_type' {aka 'int'} may change value [-Wconversion]
   49 |    if(cnR <= n / 2 && n - cnR - cnt[v[i]] <= n / 2) {
      |                                         ^
towns.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |      for(int j = 0; j + 1 < cur.size(); j += 2) {
      |                     ~~~~~~^~~~~~~~~~~~
towns.cpp:68:51: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   68 |     if(!cur.size() || f[cur[0].f] != v[i]) return R;
      |                                                   ^
towns.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int j = 0; j < save.size(); j++) {
      |                    ~~^~~~~~~~~~~~~
towns.cpp:75:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   75 |     if(sz <= n / 2) return R;
      |                            ^
towns.cpp:78:18: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::map<int, int>::key_type' {aka 'int'} may change value [-Wconversion]
   78 |   cnR += cnt[v[i]];
      |                  ^
towns.cpp:80:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   80 |  return -R;
      |         ^~
towns.cpp:12:28: warning: unused parameter 'sub' [-Wunused-parameter]
   12 | 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...