제출 #758554

#제출 시각아이디문제언어결과실행 시간메모리
758554APROHACK도시들 (IOI15_towns)C++14
35 / 100
15 ms360 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, hubs; map<int, int>cuenta; 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); if(cuenta.count((distancia[2][a]+distancia[2][i]-distancia[1][i])/2))cuenta[(distancia[2][a]+distancia[2][i]-distancia[1][i])/2]++; else cuenta[(distancia[2][a]+distancia[2][i]-distancia[1][i])/2] = 1; } 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]; } int cuentaAcum = 0; for(int i = 0 ; i < n ; i ++){ if(i == 0)cuenta[listaDist[i]]++; if(max(listaDist[i], distancia[2][a]-listaDist[i]) == minimum){ hubs.pb(i); //cout << "hub " << minimum << " : " << cuentaAcum << " " << cuenta[listaDist[i]] << " " << n-(cuenta[listaDist[i]]+cuentaAcum) << endl; if(cuentaAcum <= n/2 and cuenta[listaDist[i]] <= n/2 and n-(cuenta[listaDist[i]]+cuentaAcum) <= n/2){ return minimum; } } cuentaAcum += cuenta[listaDist[i]]; } return -minimum; /* 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; }

컴파일 시 표준 에러 (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...