이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int di0[MAXN], di1[MAXN];
void findLocation(int N, int first, int location[], int stype[]) {
location[0] = first;
stype[0] = 1;
if(N == 1)
return;
int anchor, gap = 3 * N;
for(int i = 1; i < N; i++) {
di0[i] = getDistance(0, i);
if(di0[i] < gap) {
gap = di0[i];
anchor = i;
}
}
di1[0] = gap;
location[anchor] = first + gap;
stype[anchor] = 2;
for(int i = 1; i < N; i++) {
if(i == anchor)
continue;
di1[i] = getDistance(anchor, i);
}
vector<pair<int, int>> left, right;
for(int i = 1; i < N; i++) {
if(i == anchor)
continue;
if(di0[i] == gap + di1[i]) {
// station is to the left of anchor
if(di1[i] < gap) {
// downward station for sure
location[i] = location[anchor] - di1[i];
stype[i] = 1;
}
else
left.push_back({di1[i], i});
}
else {
// station is to the right of anchor
right.push_back({di0[i], i});
}
}
sort(left.begin(), left.end());
sort(right.begin(), right.end());
// Find right
int R = anchor;
for(auto p : right) {
int sta = p.second;
int ex = getDistance(R, sta);
if(di0[sta] != di0[R] + ex) {
// further upward station
location[sta] = location[0] + di0[sta];
stype[sta] = 2;
R = sta;
}
else {
// downward
location[sta] = location[R] - ex;
stype[sta] = 1;
}
}
// Find left
int L = 0;
for(auto p : left) {
int sta = p.second;
int ex = getDistance(L, sta);
if(di1[sta] != di1[L] + ex) {
// further downward station
location[sta] = location[anchor] - di1[sta];
stype[sta] = 1;
L = sta;
}
else {
// upward
location[sta] = location[L] + ex;
stype[sta] = 2;
}
}
//for(int i = 0; i < N; i++)
// cerr << location[i] << " " << stype[i] << '\n';
return;
}
컴파일 시 표준 에러 (stderr) 메시지
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:25:14: warning: 'anchor' may be used uninitialized in this function [-Wmaybe-uninitialized]
25 | location[anchor] = first + gap;
| ^~~~~~
# | 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... |