이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;
const int mxn = 120;
#define pii pair<int,int>
#define fs first
#define sc second
int dp[mxn][mxn];
int ask(int a,int b){
if(a == b)return dp[a][b] = 0;
if(dp[a][b] != -1)return dp[a][b];
else return dp[a][b] = dp[b][a] = getDistance(a,b);
}
int tocen(int a,int b,int c){
return ((ask(a,b)+ask(a,c)-ask(b,c))>>1);
}
int hubDistance(int N, int sub) {
memset(dp,-1,sizeof(dp));
int ans = 1e9;
int s = 0,e = 0;
for(int i = 1;i<N;i++){
if(ask(s,i)>ask(s,e))e = i;
}
s = e;
for(int i = 0;i<N;i++){
if(i == s)continue;
if(ask(s,i)>ask(s,e))e = i;
}
vector<pii> v;
int len = ask(s,e);
cerr<<"[s,e]: "<<s<<' '<<e<<endl;
for(int i = 0;i<N;i++){
if(i == s||i == e)continue;
int d1 = tocen(s,i,e);
int d2 = tocen(e,i,s);
assert(d1+d2 == len);
int d3 = tocen(i,s,e);
v.push_back(pii(d1,d3));
}
sort(v.begin(),v.end());
vector<pii> vv;
for(auto &i:v){
if(!vv.empty()&&vv.back().fs == i.fs)vv.back().sc = max(vv.back().sc,i.sc);
else vv.push_back(i);
}
v.swap(vv);
//cerr<<s<<' '<<e<<":";for(auto &j:v)cerr<<j.fs<<','<<j.sc<<' ';cerr<<endl;
vector<int> mx(v.size(),0);
int pref = 0;
for(int i = 0;i<v.size();i++){
mx[i] = max({mx[i],v[i].sc,v[i].fs+pref});
pref = max(pref,-v[i].fs+v[i].sc);
}
int suf = len;
for(int i = (int)v.size()-1;i>=0;i--){
mx[i] = max({mx[i],suf-v[i].fs,v[i].sc});
suf = max(suf,v[i].fs+v[i].sc);
}
ans = min(ans,*min_element(mx.begin(),mx.end()));
//cerr<<s<<' '<<e<<":"<<ans<<endl;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0;i<v.size();i++){
| ~^~~~~~~~~
towns.cpp:24:28: warning: unused parameter 'sub' [-Wunused-parameter]
24 | int hubDistance(int N, int sub) {
| ~~~~^~~
# | 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... |