제출 #399703

#제출 시각아이디문제언어결과실행 시간메모리
399703peuchTowns (IOI15_towns)C++17
25 / 100
24 ms492 KiB
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1e6;

int dist[3][MAXN];

int hubDistance(int N, int sub) {
	int p1 = 0, p2 = 0;
	int maxi = 0;
	for(int i = 0; i < N; i++){
		int aux = getDistance(0, i);
		if(aux > maxi) p1 = i, maxi = aux;
	}
	maxi = 0;
	for(int i = 0; i < N; i++){
		dist[0][i] = getDistance(p1, i);
		if(dist[0][i] > maxi) maxi = dist[0][i], p2 = i;
	}
	for(int i = 0; i < N; i++)
		dist[1][i] = getDistance(p2, i);
	
	int diam = dist[0][p2];
	int ans = MAXN;
	for(int i = 0; i < N; i++){
		int x = (diam + dist[0][i] - dist[1][i]) / 2;
		ans = min(ans, max(x, diam - x));
	}
	
	int lSize, rSize;
	vector<int> lMid, rMid;
	for(int i = 0; i < N; i++){
		int x = (diam + dist[0][i] - dist[1][i]) / 2;
		if(x < min(ans, diam - ans)) lSize++;
		else if(x == min(ans, diam - ans)) lMid.push_back(i); 
		else if(x == max(ans, diam - ans)) rMid.push_back(i);
		else rSize++;
	}
	
	if(lSize > N / 2 || rSize > N / 2) return -ans;
	
	if(lMid.size() + lSize > N / 2){
		if(lMid.size() <= N / 2) return ans;
		return -ans;
	}
	else if(rMid.size() + rSize > N / 2){
		if(rMid.size() <= N / 2) return ans;
		return -ans;
	}
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:43:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |  if(lMid.size() + lSize > N / 2){
      |     ~~~~~~~~~~~~~~~~~~~~^~~~~~~
towns.cpp:44:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |   if(lMid.size() <= N / 2) return ans;
      |      ~~~~~~~~~~~~^~~~~~~~
towns.cpp:47:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |  else if(rMid.size() + rSize > N / 2){
      |          ~~~~~~~~~~~~~~~~~~~~^~~~~~~
towns.cpp:48:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |   if(rMid.size() <= N / 2) return ans;
      |      ~~~~~~~~~~~~^~~~~~~~
towns.cpp:9:28: warning: unused parameter 'sub' [-Wunused-parameter]
    9 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~
towns.cpp:31:13: warning: 'rSize' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |  int lSize, rSize;
      |             ^~~~~
towns.cpp:31:6: warning: 'lSize' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |  int lSize, rSize;
      |      ^~~~~
#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...