Submission #590911

#TimeUsernameProblemLanguageResultExecution timeMemory
590911FatihSolakTowns (IOI15_towns)C++17
35 / 100
26 ms728 KiB
#include "towns.h" #include <bits/stdc++.h> #define N 200 using namespace std; int dist[N][N]; int get(int i,int j){ if(i > j)swap(i,j); if(i == j)return 0; if(dist[i][j])return dist[i][j]; return dist[i][j] = getDistance(i,j); } int cnt[N]; int child_cnt[N]; int hubDistance(int n, int sub) { for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ dist[i][j] = 0; } } int root = 0; for(int i = 1;i<n;i++){ if(get(0,i) > get(0,root)) root = i; } int deepest = 0; for(int i = 1;i<n;i++){ if(get(root,i) > get(root,deepest)) deepest = i; } set<int> depths; map<int,int> mp; for(int i = 0;i<n;i++){ depths.insert( (get(root,deepest) + get(root,i) -get(deepest,i) )/2); mp[(get(root,deepest) + get(root,i) -get(deepest,i) )/2]++; } int mini = 1e9; vector<int> v; for(auto u:depths){ v.push_back(u); mini = min(mini,max(u,get(root,deepest)-u)); } vector<int> candidates; for(int i = v.size()-1;i>=0;i--){ cnt[i] = mp[v[i]]; child_cnt[i] = 0; if(i+1 != v.size()) child_cnt[i] = cnt[i+1]; cnt[i] += child_cnt[i]; //cout << v[i] << " "<< cnt[i] << endl; if(max(v[i],get(root,deepest)-v[i]) == mini && child_cnt[i] <= n/2 && (n - cnt[i]) <= n/2){ candidates.push_back(i); } } int sign = 1; if(candidates.empty())sign = -1; if(candidates.size() == 1){ //cout << (n - child_cnt[candidates[0]] - (n - cnt[candidates[0]])) << endl; if((n - child_cnt[candidates[0]] - (n - cnt[candidates[0]])) > n/2) sign = -1; } return mini * sign; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:43:22: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   43 |  for(int i = v.size()-1;i>=0;i--){
      |              ~~~~~~~~^~
towns.cpp:46:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   if(i+1 != v.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...