답안 #837604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837604 2023-08-25T12:44:12 Z oscar1f 도시들 (IOI15_towns) C++17
25 / 100
12 ms 392 KB
#include<bits/stdc++.h>
#include "towns.h"

using namespace std;

const int MAX_SOM=115,INFINI=1000*1000*1000;
int nbSom,deb,fin,rep,distDeb,distFin,taille,distMid;
int dist[MAX_SOM][MAX_SOM];
int distCentro[MAX_SOM];

int calcDist(int a,int b) {
	if (a==b) {
		return 0;
	}
	if (a>b) {
		swap(a,b);
	}
	if (dist[a][b]!=-1) {
		return dist[a][b];
	}
	dist[a][b]=getDistance(a,b);
	return dist[a][b];
}

int plusLoin(int a) {
	int posMax=0,valMax=0;
	for (int i=0;i<nbSom;i++) {
		if (calcDist(a,i)>valMax) {
			valMax=calcDist(a,i);
			posMax=i;
		}
	}
	return posMax;
}

int hubDistance(int N, int sub) {
	nbSom=N;
	for (int i=0;i<nbSom;i++) {
		for (int j=0;j<nbSom;j++) {
			dist[i][j]=-1;
		}
		distCentro[i]=0;
	}
	deb=plusLoin(0);
	fin=plusLoin(deb);
	/*cout<<deb<<" "<<fin<<endl;
	for (int i=0;i<nbSom;i++) {
		for (int j=0;j<nbSom;j++) {
			cout<<dist[i][j]<<" ";
		}
		cout<<endl;
	}*/
	rep=INFINI;
	for (int i=0;i<nbSom;i++) {
		if (i!=deb and i!=fin) {
			distDeb=(calcDist(deb,fin)+calcDist(deb,i)-calcDist(i,fin))/2;
			distFin=(calcDist(deb,fin)-calcDist(deb,i)+calcDist(i,fin))/2;
			if (max(distDeb,distFin)<rep) {
				rep=max(distDeb,distFin);
				distCentro[deb]=distDeb;
				distCentro[fin]=distFin;
			}
		}
	}
	if (sub<=2) {
		return rep;
	}
	for (int i=0;i<nbSom;i++) {
		if (i!=deb and i!=fin) {
			distMid=(calcDist(deb,i)+calcDist(i,fin)-calcDist(deb,fin))/2;
			if (calcDist(deb,i)<calcDist(fin,i)) {
				distCentro[i]=distCentro[deb]+2*distMid-calcDist(deb,i);
			}
			else {
				distCentro[i]=distCentro[fin]+2*distMid-calcDist(fin,i);
			}
		}
		//cout<<i<<" : "<<distCentro[i]<<endl;
	}
	for (int i=0;i<nbSom;i++) {
		taille=0;
		for (int j=0;j<nbSom;j++) {
			if (distCentro[i]+distCentro[j]>calcDist(i,j)) {
				taille++;
			}
		}
		//cout<<i<<" : "<<taille<<endl;
		if (taille>nbSom/2) {
			return -rep;
		}
	}
	return rep;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 340 KB Output is correct
2 Correct 9 ms 388 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 12 ms 392 KB Output is correct
5 Correct 12 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 340 KB Output is correct
2 Correct 9 ms 340 KB Output is correct
3 Correct 12 ms 340 KB Output is correct
4 Correct 12 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -