Submission #296884

#TimeUsernameProblemLanguageResultExecution timeMemory
296884tmwilliamlin168Towns (IOI15_towns)C++14
100 / 100
21 ms1152 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; const int mxN=110; int d[mxN][mxN], b[mxN], c[mxN]; int qry(int i, int j) { if(i^j&&!d[i][j]) d[i][j]=d[j][i]=getDistance(i, j); return d[i][j]; } int hubDistance(int n, int sub) { memset(d, 0, sizeof(d)); array<int, 2> a{}; for(int i=1; i<n; ++i) a=max(array<int, 2>{qry(0, i), i}, a); int di=0, ans=1e6, sl=0, sr=n; for(int i=0; i<n; ++i) di=max(qry(a[1], i), di); map<int, vector<int>> mp; for(int i=0, c; i<n; ++i) { b[i]=(qry(0, i)+qry(a[1], i)-qry(0, a[1]))/2; c=qry(a[1], i)-b[i]; mp[c].push_back(i); ans=min(max(c, di-c), ans); } for(auto p : mp) { sr-=p.second.size(); if(max(p.first, di-p.first)==ans&&sl<=n/2&&sr<=n/2) { // cout << "hi" << p.first << endl; vector<vector<int>> u, v; for(int i : p.second) { // cout << i << endl; if(u.size()&&u.back().size()>v.back().size()) { if(qry(u.back()[0], i)<b[u.back()[0]]+b[i]) u.back().push_back(i);//, cout << "same" << endl; else v.back().push_back(i);//, cout << "diff" << endl; } else { // cout << "restart" << endl; u.push_back({i}); v.push_back({}); } } int m=u.back().size(); for(int i=0; i<u.size()-1; ++i) { if(qry(u.back()[0], u[i][0])<b[u.back()[0]]+b[u[i][0]]) m+=u[i].size(); else for(int j : v[i]) m+=qry(u.back()[0], j)<b[u.back()[0]]+b[j]; } if(m<=n/2) ans=-ans; } sl+=p.second.size(); } return -ans; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:23:15: warning: declaration of 'c' shadows a global declaration [-Wshadow]
   23 |  for(int i=0, c; i<n; ++i) {
      |               ^
towns.cpp:6:26: note: shadowed declaration is here
    6 | int d[mxN][mxN], b[mxN], c[mxN];
      |                          ^
towns.cpp:30:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   30 |   sr-=p.second.size();
      |                     ^
towns.cpp:47:23: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   47 |    int m=u.back().size();
      |          ~~~~~~~~~~~~~^~
towns.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int i=0; i<u.size()-1; ++i) {
      |                 ~^~~~~~~~~~~
towns.cpp:50:19: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   50 |      m+=u[i].size();
      |                   ^
towns.cpp:58:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   58 |   sl+=p.second.size();
      |                     ^
towns.cpp:14:28: warning: unused parameter 'sub' [-Wunused-parameter]
   14 | 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...