Submission #758549

#TimeUsernameProblemLanguageResultExecution timeMemory
758549APROHACKTowns (IOI15_towns)C++14
25 / 100
15 ms1092 KiB
#include "towns.h" #include <bits/stdc++.h> #define ll long long #define ff first #define ss second #define pb push_back using namespace std; int n, nodes; int x, a, b; int distancia[5][120]; int hubDistance(int N, int sub) { n = N; nodes = n; x = 0; distancia[0][x] = 0; int masLejano = 0; for(int i = 0 ; i < N ; i ++){ if(i == x)continue; distancia[0][i] = getDistance(x, i); if(distancia[0][i] > distancia[0][masLejano]){ masLejano = i; } } a = masLejano; // A encontrado, buscando B masLejano = a; distancia[1][a] = 0; distancia[1][x] = distancia[0][a]; for(int i = 0 ; i < N ; i ++){ if(i == x or i == a)continue; distancia[1][i] = getDistance(a, i); if(distancia[1][i] > distancia[1][masLejano])masLejano = i; } if(distancia[0][a] > distancia[1][masLejano]){ b = x; for(int i = 0 ; i < N ; i ++){ distancia[2][i] = distancia[0][i]; } x = 0; while(x == a or x == b)x++; distancia[0][a] = distancia[1][x]; distancia[0][b] = distancia[2][x]; distancia[0][x] = 0; for(int i = 0 ; i < N ; i ++){ if(i == a or i == b or i == x)continue; distancia[0][i] = getDistance(x, i); } }else{ b = masLejano; distancia[2][a] = distancia[1][b]; distancia[2][x] = distancia[0][b]; for(int i = 0 ; i < N ; i ++){ if(i == a or i == b or i == x)continue; distancia[2][i] = getDistance(b, i); } } set<int>st; vector<int>listaDist, caminos; for(int i = 0 ; i < n ; i ++){ if(i == a or i == b)continue; st.insert((distancia[2][a]+distancia[2][i]-distancia[1][i])/2); } for(auto i : st)listaDist.pb(i); listaDist.pb(distancia[2][a]); int anterior = 0; int minimum = INT_MAX; for(int i = 0 ; i < n ; i ++){ caminos.pb(listaDist[i]-anterior); minimum = min(minimum, max(listaDist[i], distancia[2][a]-listaDist[i])); anterior = listaDist[i]; } /* cout << "X = " << x << endl; for(int i = 0 ; i < N ; i++){ cout << "dist with " << i << " = " << distancia[0][i] << endl; } cout << "A = " << a << endl; for(int i = 0 ; i < N ; i++){ cout << "dist with " << i << " = " << distancia[1][i] << endl; } cout << "B = " << b << endl; for(int i = 0 ; i < N ; i++){ cout << "dist with " << i << " = " << distancia[2][i] << endl; } */ //for(auto i : listaDist)cout << i << " "; //cout << endl; return minimum; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:11:28: warning: unused parameter 'sub' [-Wunused-parameter]
   11 | 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...