답안 #207284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207284 2020-03-07T03:47:01 Z AQT 도시들 (IOI15_towns) C++14
컴파일 오류
0 ms 0 KB
//#include <towns.h>
#include <bits/stdc++.h>

using namespace std;

int dist[2][200];
int par[200], sz[200];
bool midset[200];

int hubDistance(int N, int sub){
    int d1 = 0, d2 = 0;
    for(int i = 1; i<N; i++){
        dist[0][i] = getDistance(0, i);
        if(dist[0][i] > dist[0][d1]){
            d1 = i;
        }
    }
    for(int i = 0; i<N; i++){
        dist[1][i] = getDistance(d1, i);
        if(dist[1][i] > dist[1][d2]){
            d2 = i;
        }
    }
    int dia = dist[1][d2];
    int ans = dia;
    for(int i = 0; i<N; i++){
        int k = (dist[0][d1] + dist[1][i] - dist[0][i])/2;
        if(abs(ans-dia/2) > abs(k-dia/2)){
            ans = k;
        }
        midset[i] = 0;
    }
    ans = max(ans, dia-ans);
    int lft = 0, rht = 0;
    for(int i = 0; i<N; i++){
        int k = (dist[0][d1] + dist[1][i] - dist[0][i])/2;
        if(dia-k > ans){
            midset[i] = 1;
            lft++;
        }
        else if(k > ans){
            midset[i] = 1;
            rht++;
        }
    }
    if(max(lft, rht) > N/2){
        ans = -ans;
        return ans;
    }
    vector<int> v, w, t;
    for(int i =0 ; i<N; i++){
        if(midset[i]){
            continue;
        }
        par[i] = i;
        v.push_back(i);
        sz[i] = 1;
    }
    int g = -1;
    for(int k = 0; k<10; k++){
        while(v.size() >= 2){
            int n = v.back();
            v.pop_back();
            int m = v.back();
            v.pop_back();
            if(dist[1][n] + dist[1][m] - getDistance(n, m) > dia){
                par[n] = -1;
                sz[m] += sz[n];
                w.push_back(m);
            }
            else{
                t.push_back(n);
                t.push_back(m);
            }
        }
        if(v.size() == 1 && w.empty()){
            g = v[0];
            break;
        }
        swap(v, w);
    }
    if(g != -1){
        int cnt = 0;
        for(int i = 0; i<N; i++){
            if(par[i] == i){
                if(dist[1][i] + dist[1][g] - getDistance(i, g) > dia){
                    cnt += sz[i];
                }
            }
        }
        if(cnt > N/2){
            ans = -ans;
        }
    }
    else{
        ans = -ans;
    }
    return ans;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:13:22: error: 'getDistance' was not declared in this scope
         dist[0][i] = getDistance(0, i);
                      ^~~~~~~~~~~
towns.cpp:13:22: note: suggested alternative: 'hubDistance'
         dist[0][i] = getDistance(0, i);
                      ^~~~~~~~~~~
                      hubDistance
towns.cpp:19:22: error: 'getDistance' was not declared in this scope
         dist[1][i] = getDistance(d1, i);
                      ^~~~~~~~~~~
towns.cpp:19:22: note: suggested alternative: 'hubDistance'
         dist[1][i] = getDistance(d1, i);
                      ^~~~~~~~~~~
                      hubDistance
towns.cpp:66:42: error: 'getDistance' was not declared in this scope
             if(dist[1][n] + dist[1][m] - getDistance(n, m) > dia){
                                          ^~~~~~~~~~~
towns.cpp:66:42: note: suggested alternative: 'hubDistance'
             if(dist[1][n] + dist[1][m] - getDistance(n, m) > dia){
                                          ^~~~~~~~~~~
                                          hubDistance
towns.cpp:86:46: error: 'getDistance' was not declared in this scope
                 if(dist[1][i] + dist[1][g] - getDistance(i, g) > dia){
                                              ^~~~~~~~~~~
towns.cpp:86:46: note: suggested alternative: 'hubDistance'
                 if(dist[1][i] + dist[1][g] - getDistance(i, g) > dia){
                                              ^~~~~~~~~~~
                                              hubDistance
towns.cpp:10:28: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int N, int sub){
                            ^~~