Submission #805622

#TimeUsernameProblemLanguageResultExecution timeMemory
805622FatihSolakTowns (IOI15_towns)C++17
25 / 100
16 ms468 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; int hubDistance(int N, int sub) { map<int,int> d[N]; auto get = [&](int a,int b){ if(a > b) swap(a,b); if(d[a].count(b)) return d[a][b]; if(a == b) return 0; return d[a][b] = getDistance(a,b); }; int v = 0; for(int i = 0;i<N;i++){ if(get(0,i) > get(0,v)){ v = i; } } int x = 0; for(int i = 0;i<N;i++){ if(get(v,i) > get(v,x)){ x = i; } } int len = get(v,x); // cout << v << ' ' << x << ' ' << len << endl; map<int,vector<int>> mp; for(int i = 0;i<N;i++){ int val = (get(0,i) + get(0,v) - get(v,i))/2; mp[val].push_back(i); } int val1 = 0; int val2 = 2e9; int ans; for(auto u:mp){ int tmp = get(0,v) - u.first; // cout << tmp << endl; if(tmp <= len/2){ val1 = max(val1,tmp); } if((len + 1)/2 <= tmp){ val2 = min(val2,tmp); } } // cout << val1 << ' ' << val2 << endl; ans = len - val1; if(val2 != len - val1){ if(val2 < len - val1){ ans = val2; val1 = -1; } else val2 = -1; } int cnt = 0; for(auto u:mp){ int tmp = get(0,v) - u.first; if(tmp == val1){ if(cnt > N/2 || (N-cnt-u.second.size()) > N/2){ val1 = -1; } } if(tmp == val2){ if(cnt > N/2 || (N-cnt-u.second.size()) > N/2){ val2 = -1; } } cnt += u.second.size(); } if(val1 == -1 && val2 == -1) return -ans; if(val1 == -1) val1 = val2; vector<int> a = mp[-(val1 - get(0,v))]; vector<int> v1,v2; for(auto u:a){ if(v1.empty() || get(u,v1.back()) == get(v,u) + get(v,v1.back()) - 2 * val1){ v1.push_back(u); if(v2.size()){ v1.push_back(v2.back()); v2.pop_back(); } } else v2.push_back(u); } if(v2.empty()) return -ans; cnt = 0; // for(auto u:a){ // if(get(u,v2[0]) != get(v,u) + get(v,v2[0]) - 2 * val1){ // cnt++; // } // } if(cnt <= N/2) return ans; return -ans; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:60:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |    if(cnt > N/2 || (N-cnt-u.second.size()) > N/2){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
towns.cpp:65:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |    if(cnt > N/2 || (N-cnt-u.second.size()) > N/2){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
towns.cpp:69:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   69 |   cnt += u.second.size();
      |                        ^
towns.cpp:4:28: warning: unused parameter 'sub' [-Wunused-parameter]
    4 | 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...