답안 #891818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891818 2023-12-24T06:28:36 Z abcvuitunggio 도시들 (IOI15_towns) C++17
0 / 100
13 ms 536 KB
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
int n,dist[111][111],cnt,u,v,R,sz[2];
int d(int u, int v){
    if (u==v)
        return 0;
    if (u>v)
        swap(u,v);
    if (dist[u][v])
        return dist[u][v];
    cnt++;
    if (cnt>(n*7+1)/2)
        return 0;
    return dist[u][v]=getDistance(u,v);
}
int calc(vector <int> ve){
    vector <int> l,r;
    int j=ve.back();
    l.push_back(j);
    ve.pop_back();
    int pos=0;
    for (int i:ve){
        if (max(l.size(),r.size())+ve.size()-pos+1<=n/2)
            return R;
        pos++;
        int c=1;
        int x=(d(i,u)+d(i,v)-d(u,v))/2,y=(d(j,u)+d(j,v)-d(u,v))/2;
        if (d(i,j)<x+y){
            l.push_back(i);
            if (l.size()>n/2)
                return -R;
        }
        else
            r.push_back(i);
    }
    return calc(r);
}
int hubDistance(int N, int sub){
    n=N;
    memset(dist,0,sizeof(dist));
    pair <int, int> mx={0,-1};
    for (int i=0;i<N;i++)
        mx=max(mx,{d(0,i),i});
    u=mx.second;
    mx={0,-1};
    for (int i=0;i<N;i++)
        mx=max(mx,{d(u,i),i});
    v=mx.second,R=1e9,sz[0]=sz[1]=0;
	for (int i=0;i<N;i++)
        R=min(R,abs(d(i,u)-d(i,v)));
    vector <int> a,b,tmp;
    for (int i=0;i<N;i++){
        int val=d(i,u)-d(i,v);
        if (val<-R)
            sz[0]++;
        if (val==-R)
            a.push_back(i);
        if (val==R)
            b.push_back(i);
        if (val>R)
            sz[1]++;
    }
    if (!R)
        b.clear();
    R=(R+d(u,v))/2;
    if (sub<3)
        return R;
    if (max(sz[0],sz[1])>N/2)
        return -R;
    if (min(sz[1]+b.size(),sz[0]+a.size())>N/2)
        return -R;
    if (max(a.size(),sz[1]+b.size())<=N/2)
        return R;
    if (max(b.size(),sz[0]+a.size())<=N/2)
        return R;
    return calc(b.size()+sz[1]<=N/2?a:b);
}

Compilation message

towns.cpp: In function 'int d(int, int)':
towns.cpp:5:18: warning: declaration of 'v' shadows a global declaration [-Wshadow]
    5 | int d(int u, int v){
      |              ~~~~^
towns.cpp:4:28: note: shadowed declaration is here
    4 | int n,dist[111][111],cnt,u,v,R,sz[2];
      |                            ^
towns.cpp:5:11: warning: declaration of 'u' shadows a global declaration [-Wshadow]
    5 | int d(int u, int v){
      |       ~~~~^
towns.cpp:4:26: note: shadowed declaration is here
    4 | int n,dist[111][111],cnt,u,v,R,sz[2];
      |                          ^
towns.cpp: In function 'int calc(std::vector<int>)':
towns.cpp:24:51: warning: comparison of integer expressions of different signedness: 'long unsigned int' and 'int' [-Wsign-compare]
   24 |         if (max(l.size(),r.size())+ve.size()-pos+1<=n/2)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
towns.cpp:31:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |             if (l.size()>n/2)
      |                 ~~~~~~~~^~~~
towns.cpp:27:13: warning: unused variable 'c' [-Wunused-variable]
   27 |         int c=1;
      |             ^
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:71:43: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
   71 |     if (min(sz[1]+b.size(),sz[0]+a.size())>N/2)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
towns.cpp:73:37: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
   73 |     if (max(a.size(),sz[1]+b.size())<=N/2)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
towns.cpp:75:37: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
   75 |     if (max(b.size(),sz[0]+a.size())<=N/2)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
towns.cpp:77:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   77 |     return calc(b.size()+sz[1]<=N/2?a:b);
      |                 ~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -