Submission #257149

#TimeUsernameProblemLanguageResultExecution timeMemory
257149eohomegrownapps도시들 (IOI15_towns)C++14
Compilation error
0 ms0 KiB
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<ll>> distv;
ll n;

ll gd;

ll dist(ll a, ll b){
    if (a==b){return 0;}
    if (a>b){
        swap(a,b);
    }
    if (distv[a][b]!=-1){
        return distv[a][b];
    } else {
        gd++;
        assert(gd<=(n*(n-1))/2);
        return distv[a][b]=getDistance(a,b);
    }
}

int hubDistance(int N, int sub) {
    gd=0;
    n=N;
    distv.assign(n,vector<ll>(n,-1));
	
    ll adist = -1;
    ll aind = -1;
    for (ll i = 0; i<n; i++){
        ll ds = dist(0,i);
        if (adist<ds){
            adist=ds;
            aind=i;
        }
    }


    ll bdist = -1;
    ll bind = -1;
    for (ll i = 0; i<n; i++){
        ll ds = dist(aind,i);
        if (bdist<ds){
            bdist=ds;
            bind=i;
        }
    }

    //from adist to aind
    //vector<ll> diameter;
    ll hubdist = 1e18;
    ll hubind = -1;
    for (ll i = 0; i<n; i++){
        if (i==aind||i==bind){continue;}
        ll distfroma = dist(aind,i)-(dist(aind,i)+dist(bind,i)-dist(aind,bind))/2;
        ll rv = max(distfroma,dist(aind,bind)-distfroma);
        if (rv<hubdist){
            hubdist=rv;
            hubind=i;
        }
    }
    if (sub<=2){return hubdist;}
	ll hubfroma = dist(aind,hubind)-(dist(aind,hubind)+dist(bind,hubind)-dist(aind,bind))/2;;
    vector<ll> nodesinhub;
    ll befcnt=0;
    ll aftcnt=0;
    for (ll i = 0; i<n; i++){
        ll distfroma = dist(aind,i)-(dist(aind,i)+dist(bind,i)-dist(aind,bind))/2;
        if (distfroma<hubfroma){
            befcnt++;
        } else if (distfroma==hubfroma){
            nodesinhub.push_back(i);
        } else {
            aftcnt++;
        }
    }
    //cout<<befcnt<<' '<<aftcnt<<' '<<nodesinhub.size()<<'\n';
    if (befcnt>n/2||aftcnt>n/2){return -hubdist;}
    vector<bool> visited(n,false);
    ll nodesleft = nodesinhub.size();
    for (ll i : nodesinhub){
        if (visited[i]){continue;}
        if (nodesleft<=n/2){break;}
        ll nodesingrp = 1;
        visited[i]=true;
        for (ll j : nodesinhub){
            if (!visited[j]){
                if (dist(i,j)<dist(aind,i)+dist(aind,j)-2*hubfroma){
                    nodesingrp++;
                    visited[j]=true;
                }
            }
        }
        //cout<<nodesingrp<<'\n';
        if (nodesingrp>n/2){return -hubdist;}
        nodesleft-=nodesingrp;
    }
    return hubdist;
}

Compilation message (stderr)

towns.cpp:5:15: error: 'll' was not declared in this scope
 vector<vector<ll>> distv;
               ^~
towns.cpp:5:15: error: template argument 1 is invalid
towns.cpp:5:15: error: template argument 2 is invalid
towns.cpp:5:17: error: template argument 1 is invalid
 vector<vector<ll>> distv;
                 ^~
towns.cpp:5:17: error: template argument 2 is invalid
towns.cpp:6:1: error: 'll' does not name a type
 ll n;
 ^~
towns.cpp:8:1: error: 'll' does not name a type
 ll gd;
 ^~
towns.cpp:10:1: error: 'll' does not name a type
 ll dist(ll a, ll b){
 ^~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:25:5: error: 'gd' was not declared in this scope
     gd=0;
     ^~
towns.cpp:26:5: error: 'n' was not declared in this scope
     n=N;
     ^
towns.cpp:27:11: error: request for member 'assign' in 'distv', which is of non-class type 'int'
     distv.assign(n,vector<ll>(n,-1));
           ^~~~~~
towns.cpp:27:27: error: 'll' was not declared in this scope
     distv.assign(n,vector<ll>(n,-1));
                           ^~
towns.cpp:27:29: error: template argument 1 is invalid
     distv.assign(n,vector<ll>(n,-1));
                             ^
towns.cpp:27:29: error: template argument 2 is invalid
towns.cpp:29:8: error: expected ';' before 'adist'
     ll adist = -1;
        ^~~~~
towns.cpp:30:8: error: expected ';' before 'aind'
     ll aind = -1;
        ^~~~
towns.cpp:31:13: error: expected ';' before 'i'
     for (ll i = 0; i<n; i++){
             ^
towns.cpp:31:20: error: 'i' was not declared in this scope
     for (ll i = 0; i<n; i++){
                    ^
towns.cpp:32:12: error: expected ';' before 'ds'
         ll ds = dist(0,i);
            ^~
towns.cpp:33:13: error: 'adist' was not declared in this scope
         if (adist<ds){
             ^~~~~
towns.cpp:33:13: note: suggested alternative: 'distv'
         if (adist<ds){
             ^~~~~
             distv
towns.cpp:33:19: error: 'ds' was not declared in this scope
         if (adist<ds){
                   ^~
towns.cpp:35:13: error: 'aind' was not declared in this scope
             aind=i;
             ^~~~
towns.cpp:35:13: note: suggested alternative: 'rand'
             aind=i;
             ^~~~
             rand
towns.cpp:40:8: error: expected ';' before 'bdist'
     ll bdist = -1;
        ^~~~~
towns.cpp:41:8: error: expected ';' before 'bind'
     ll bind = -1;
        ^~~~
towns.cpp:42:13: error: expected ';' before 'i'
     for (ll i = 0; i<n; i++){
             ^
towns.cpp:42:20: error: 'i' was not declared in this scope
     for (ll i = 0; i<n; i++){
                    ^
towns.cpp:43:12: error: expected ';' before 'ds'
         ll ds = dist(aind,i);
            ^~
towns.cpp:44:13: error: 'bdist' was not declared in this scope
         if (bdist<ds){
             ^~~~~
towns.cpp:44:13: note: suggested alternative: 'distv'
         if (bdist<ds){
             ^~~~~
             distv
towns.cpp:44:19: error: 'ds' was not declared in this scope
         if (bdist<ds){
                   ^~
towns.cpp:52:8: error: expected ';' before 'hubdist'
     ll hubdist = 1e18;
        ^~~~~~~
towns.cpp:53:8: error: expected ';' before 'hubind'
     ll hubind = -1;
        ^~~~~~
towns.cpp:54:13: error: expected ';' before 'i'
     for (ll i = 0; i<n; i++){
             ^
towns.cpp:54:20: error: 'i' was not declared in this scope
     for (ll i = 0; i<n; i++){
                    ^
towns.cpp:55:16: error: 'aind' was not declared in this scope
         if (i==aind||i==bind){continue;}
                ^~~~
towns.cpp:55:16: note: suggested alternative: 'rand'
         if (i==aind||i==bind){continue;}
                ^~~~
                rand
towns.cpp:56:12: error: expected ';' before 'distfroma'
         ll distfroma = dist(aind,i)-(dist(aind,i)+dist(bind,i)-dist(aind,bind))/2;
            ^~~~~~~~~
towns.cpp:57:12: error: expected ';' before 'rv'
         ll rv = max(distfroma,dist(aind,bind)-distfroma);
            ^~
towns.cpp:58:13: error: 'rv' was not declared in this scope
         if (rv<hubdist){
             ^~
towns.cpp:58:16: error: 'hubdist' was not declared in this scope
         if (rv<hubdist){
                ^~~~~~~
towns.cpp:60:13: error: 'hubind' was not declared in this scope
             hubind=i;
             ^~~~~~
towns.cpp:60:13: note: suggested alternative: 'rewind'
             hubind=i;
             ^~~~~~
             rewind
towns.cpp:63:24: error: 'hubdist' was not declared in this scope
     if (sub<=2){return hubdist;}
                        ^~~~~~~
towns.cpp:64:5: error: expected ';' before 'hubfroma'
  ll hubfroma = dist(aind,hubind)-(dist(aind,hubind)+dist(bind,hubind)-dist(aind,bind))/2;;
     ^~~~~~~~
towns.cpp:65:14: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'
     vector<ll> nodesinhub;
              ^
towns.cpp:65:14: note:   expected a type, got 'll'
towns.cpp:65:14: error: template argument 2 is invalid
towns.cpp:66:8: error: expected ';' before 'befcnt'
     ll befcnt=0;
        ^~~~~~
towns.cpp:67:8: error: expected ';' before 'aftcnt'
     ll aftcnt=0;
        ^~~~~~
towns.cpp:68:13: error: expected ';' before 'i'
     for (ll i = 0; i<n; i++){
             ^
towns.cpp:68:20: error: 'i' was not declared in this scope
     for (ll i = 0; i<n; i++){
                    ^
towns.cpp:69:12: error: expected ';' before 'distfroma'
         ll distfroma = dist(aind,i)-(dist(aind,i)+dist(bind,i)-dist(aind,bind))/2;
            ^~~~~~~~~
towns.cpp:70:13: error: 'distfroma' was not declared in this scope
         if (distfroma<hubfroma){
             ^~~~~~~~~
towns.cpp:70:23: error: 'hubfroma' was not declared in this scope
         if (distfroma<hubfroma){
                       ^~~~~~~~
towns.cpp:71:13: error: 'befcnt' was not declared in this scope
             befcnt++;
             ^~~~~~
towns.cpp:71:13: note: suggested alternative: 'qfcvt'
             befcnt++;
             ^~~~~~
             qfcvt
towns.cpp:73:24: error: request for member 'push_back' in 'nodesinhub', which is of non-class type 'int'
             nodesinhub.push_back(i);
                        ^~~~~~~~~
towns.cpp:75:13: error: 'aftcnt' was not declared in this scope
             aftcnt++;
             ^~~~~~
towns.cpp:75:13: note: suggested alternative: 'qfcvt'
             aftcnt++;
             ^~~~~~
             qfcvt
towns.cpp:79:9: error: 'befcnt' was not declared in this scope
     if (befcnt>n/2||aftcnt>n/2){return -hubdist;}
         ^~~~~~
towns.cpp:79:9: note: suggested alternative: 'qfcvt'
     if (befcnt>n/2||aftcnt>n/2){return -hubdist;}
         ^~~~~~
         qfcvt
towns.cpp:79:21: error: 'aftcnt' was not declared in this scope
     if (befcnt>n/2||aftcnt>n/2){return -hubdist;}
                     ^~~~~~
towns.cpp:79:21: note: suggested alternative: 'qfcvt'
     if (befcnt>n/2||aftcnt>n/2){return -hubdist;}
                     ^~~~~~
                     qfcvt
towns.cpp:79:41: error: 'hubdist' was not declared in this scope
     if (befcnt>n/2||aftcnt>n/2){return -hubdist;}
                                         ^~~~~~~
towns.cpp:81:8: error: expected ';' before 'nodesleft'
     ll nodesleft = nodesinhub.size();
        ^~~~~~~~~
towns.cpp:82:13: error: expected ';' before 'i'
     for (ll i : nodesinhub){
             ^
towns.cpp:99:5: error: expected primary-expression before 'return'
     return hubdist;
     ^~~~~~
towns.cpp:99:5: error: expected ';' before 'return'
towns.cpp:99:5: error: expected primary-expression before 'return'
towns.cpp:99:5: error: expected ')' before 'return'
towns.cpp:99:12: error: 'hubdist' was not declared in this scope
     return hubdist;
            ^~~~~~~