이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int len = 5005;
map<ii, int> mym;
int st1, st2;
vector<int> vec;
int dis(int a, int b){
if (a == b) return 0;
if (mym.count(mp(a, b))) return mym[mp(a, b)];
if (a > b) swap(a, b);
return mym[mp(a, b)] = getDistance(a, b);
}
bool comp1(int a, int b){
return (dis(st1, a) < dis(st1, b));
}
bool comp2(int a, int b){
return (dis(st2, a) < dis(st2, b));
}
void findLocation(int n, int first, int loc[], int stype[]){
loc[0] = first;
stype[0] = 1;
if (n == 1)
return;
st1 = 0, st2 = -1;
for (int i = 1; i < n; i++)
if (st2 == -1 || dis(st1, i) < dis(st1, st2))
st2 = i;
vec.pb(st2);
for (int i = 0; i < n; i++)
if (i != st1 && dis(st1, i) < dis(st2, i))
vec.pb(i);
sort(vec.begin(), vec.end(), comp1);
int last = -1;
for (int i = 0; i < vec.size(); i++){
int nex = vec[i];
if (last == -1 || dis(st1, nex) < dis(last, nex)){
loc[nex] = loc[st1]+dis(st1, nex);
stype[nex] = 2;
last = nex;
}
else{
loc[nex] = loc[last]-dis(last, nex);
stype[nex] = 1;
}
}
vec.clear();
vec.pb(st1);
for (int i = 0; i < n; i++)
if (i != st2 && dis(st2, i) < dis(st1, i))
vec.pb(i);
sort(vec.begin(), vec.end(), comp2);
last = -1;
for (int i = 0; i < vec.size(); i++){
int nex = vec[i];
if (last == -1 || dis(st2, nex) < dis(last, nex)){
loc[nex] = loc[st2]-dis(st2, nex);
stype[nex] = 1;
last = nex;
}
else{
loc[nex] = loc[last]+dis(last, nex);
stype[nex] = 2;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:49:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vec.size(); i++){
~~^~~~~~~~~~~~
rail.cpp:70:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vec.size(); i++){
~~^~~~~~~~~~~~
# | 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... |