이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <limits>
#include "rail.h"
#include <algorithm>
#include <cassert>
using namespace std;
void findLocation(int n, int first, int location[], int stype[]){
int fl = numeric_limits<int>::max();
int ifl;
for(int c = 1; c < n; ++c){
if(getDistance(0,c) < fl){
fl = getDistance(0,c);
ifl = c;
}
}
location[ifl] = first + fl;
stype[ifl] = 2;
int fr = numeric_limits<int>::max();
int ifr;
for(int c = 0; c < n; c++){
if(c != ifl && getDistance(ifl,c) < fr){
fr = getDistance(ifl,c);
ifr = c;
}
}
location[ifr] = first + fl - fr;
stype[ifr] = 1;
vector<vector<int>> ts;
for(int sol = 0; sol < n; sol++){
int tu = getDistance(ifl,sol);
int td = getDistance(ifr,sol);
ts.push_back({tu, td, sol});
}
sort(ts.begin(), ts.end());
vector<int> leftdowns;
vector<int> rightups;
for(vector<int> t : ts){
int tu = t[0], td = t[1], sol = t[1];
if(tu + fr == td){
for(int uc : leftdowns){
int d = getDistance(uc, sol);
if(d + (location[ifl] - location[uc]) == tu){
location[sol] = location[uc] + d;
stype[sol] = 2;
goto done;
}
}
location[sol] = location[ifl] - tu;
stype[sol] = 1;
leftdowns.push_back(sol);
done:
;
}
if(td + fr == tu){
for(int uc : rightups){
int d = getDistance(uc, sol);
if(d + (location[uc] - location[ifr]) == td){
location[sol] = location[uc] - d;
stype[sol] = 1;
goto alsodone;
}
}
location[sol] = location[ifr] + td;
stype[sol] = 2;
rightups.push_back(sol);
alsodone:
;
}
else{
//assert(false);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:20:14: warning: 'ifl' may be used uninitialized in this function [-Wmaybe-uninitialized]
20 | location[ifl] = first + fl;
| ^~~
rail.cpp:32:14: warning: 'ifr' may be used uninitialized in this function [-Wmaybe-uninitialized]
32 | location[ifr] = first + fl - fr;
| ^~~
# | 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... |