이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int d[150][150];
int dist(int i,int j){
if(i==j)return 0;
if(i>j)swap(i,j);
if(d[i][j]!=-1)return d[i][j];
int x=getDistance(i,j);
return d[i][j]=x;
}
int hubDistance(int N, int sub) {
memset(d,-1,sizeof(d));
int Max=0,s=-1;
rep(i,N){
if(Max<dist(0,i)){
Max=dist(0,i);
s=i;
}
}
Max=0;int t=-1;
rep(i,N){
if(Max<dist(s,i)){
Max=dist(s,i);
t=i;
}
}
int Min=INT_MAX;
set<int>idx;
map<int,vector<int>>mp;
rep(i,N){
int x=dist(s,i),y=dist(t,i);
int z=(x+y-Max)/2;
int a=x-z,b=y-z;
mp[a].push_back(i);
if(Min>max(a,b)){
Min=max(a,b);
}
if(Min==max(a,b)){
idx.insert(a);
}
}
if(sub<=2)return Min;
auto C=[&](int id){
int c1=0,c2=0;
for(auto p:mp){
if(p.first<id)c1+=p.second.size();
if(p.first>id)c2+=p.second.size();
}
if(c1>N/2||c2>N/2)return false;
vector<vector<int>>vs;
for(int v:mp[id]){
bool flag=false;
for(auto&V:vs){
if(dist(s,V[0])+dist(s,v)-2*id!=dist(V[0],v)){
V.push_back(v);flag=true;
if(V.size()>N/2)return false;
break;
}
}
if(!flag)vs.push_back({v});
}
return true;
};
for(int id:idx){
if(C(id))return Min;
}
return -Min;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In lambda function:
towns.cpp:51:36: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
if(p.first<id)c1+=p.second.size();
^
towns.cpp:52:36: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
if(p.first>id)c2+=p.second.size();
^
towns.cpp:61:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(V.size()>N/2)return false;
~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |