제출 #433997

#제출 시각아이디문제언어결과실행 시간메모리
43399779brue도시들 (IOI15_towns)C++14
0 / 100
16 ms460 KiB
#include <bits/stdc++.h>
#include "towns.h"

using namespace std;

typedef long long ll;

int n, k;
int x, y, len;
int a[120], b[120];

vector<int> dist;
map<int, int> idx;

int branch[120], loc[120];
vector<pair<int, int> > vec[120];
int maxB[120];

int R=1e9, C; bool twoC;
bool centroidExist;

int hubDistance(int N, int sub){
	n = N;
	x = 0;
	for(int i=0; i<n; i++){
        if(i!=x) a[i] = getDistance(x, i);
	}
	y = max_element(a, a+n) - a;
	len = a[y];
	for(int i=0; i<n; i++){
        if(i==x) b[i] = len;
        else if(i!=y) b[i] = getDistance(y, i);
	}

    dist.push_back(0);
    dist.push_back(len);
	for(int i=0; i<n; i++){
        if(i==x || i==y) continue;
        branch[i] = (a[i] + b[i] - len) / 2;
        dist.push_back(a[i] - branch[i]);
	}

	sort(dist.begin(), dist.end());
	dist.erase(unique(dist.begin(), dist.end()), dist.end());
	for(int i=0; i<(int)dist.size(); i++){
        idx[dist[i]] = i;
	}

    int k = (int)dist.size();
    for(int i=0; i<n; i++){
        if(i==x || i==y) continue;
        loc[i] = idx[a[i] - branch[i]];
        vec[loc[i]].push_back(make_pair(i, branch[i]));
        maxB[loc[i]] = max(maxB[loc[i]], branch[i]);
    }

    for(int i=1; i<k-1; i++){
        int maxLen = -1;
        for(int j=0; j<k; j++){
            maxLen = max(maxLen, abs(dist[i] - dist[j]) + maxB[j]);
        }
        if(maxLen < R){
            R = maxLen;
            C = i;
        }
        else if(maxLen == R) twoC = 1;
    }

    return R;
}

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:28:26: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   28 |  y = max_element(a, a+n) - a;
      |      ~~~~~~~~~~~~~~~~~~~~^~~
towns.cpp:49:9: warning: declaration of 'k' shadows a global declaration [-Wshadow]
   49 |     int k = (int)dist.size();
      |         ^
towns.cpp:8:8: note: shadowed declaration is here
    8 | int n, k;
      |        ^
towns.cpp:22:28: warning: unused parameter 'sub' [-Wunused-parameter]
   22 | 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...