이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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++;
}
}
if (taille>nbSom/2) {
return -rep;
}
}
return rep;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |