제출 #432101

#제출 시각아이디문제언어결과실행 시간메모리
432101Antekb도시들 (IOI15_towns)C++14
25 / 100
19 ms344 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; #define st first #define nd second int hubDistance(int N, int sub) { //int R = getDistance(0,1); int d1[N], d2[N]; d1[0]=0; for(int i=1; i<N; i++)d1[i]=getDistance(0, i); int e=0; for(int i=0; i<N; i++)if(d1[i]>d1[e])e=i; for(int i=1; i<N; i++)if(e!=i)d2[i]=getDistance(e, i); d2[e]=0; d2[0]=d1[e]; int diam=0; for(int i=0; i<N; i++)diam=max(diam, d2[i]); int R=diam; for(int i=0; i<N; i++){ if(i==0 || i==e)continue; int d=(d2[i]+d2[0]-d1[i])/2; R=min(R, max(d, diam-d)); } int a=0, b=0; vector<int> A, B; for(int i=0; i<N; i++){ if(i==0 || i==e)continue; int d=(d2[i]+d2[0]-d1[i])/2; if(d<R)a++; else if(d==R)A.push_back(i); else if(diam-d==R)B.push_back(i); else b++; } if(a>N/2)return -R; if(b>N/2)return -R; if(a+A.size()<=N/2 && B.size()<=N/2)return R; if(b+B.size()<=N/2 && A.size()<=N/2)return R; return -R; if(A.size()<B.size())swap(A, B); stack<int> S; int dist[N]; for(int i=0; i<N; i++){ dist[i]=(d2[i]-d2[0]+d1[i])/2; } stack<int> S2; for(int i:A){ if(S2.size()==0 || dist[i]+dist[S2.top()]!=getDistance(i, S2.top())){ S2.push(i); } else{ S2.push(i); if(S.size()){ S2.push(S.top()); S.pop(); } } } while(S.size() && S2.size()){ if(dist[S.top()]+dist[S2.top()]!=getDistance(S.top(), S2.top())){ S2.pop(); if(S2.size())S2.pop(); } else{ S.pop(); S2.pop(); } } if(S2.size())return R; else return -R; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:36:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |  if(a+A.size()<=N/2 && B.size()<=N/2)return R;
      |     ~~~~~~~~~~^~~~~
towns.cpp:36:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |  if(a+A.size()<=N/2 && B.size()<=N/2)return R;
      |                        ~~~~~~~~^~~~~
towns.cpp:37:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |  if(b+B.size()<=N/2 && A.size()<=N/2)return R;
      |     ~~~~~~~~~~^~~~~
towns.cpp:37:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |  if(b+B.size()<=N/2 && A.size()<=N/2)return R;
      |                        ~~~~~~~~^~~~~
towns.cpp:6:28: warning: unused parameter 'sub' [-Wunused-parameter]
    6 | 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...