이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <algorithm>
#include <stdio.h>
using namespace std;
int dis0[5010];
int disx[5010];
int bef[5010],next[5010];
int op[5010],num[5010];
bool cmp(int x,int y){
return dis0[x] < dis0[y];
}
bool cmp2(int x,int y){
return disx[x] < disx[y];
}
void findLocation(int N, int first, int location[], int stype[]){
int i,j,k;
int small,x;
int t,v,nv;
int rear,tmp;
location[0] = first; stype[0] = 1;
small = 999999999;
for(i=1; i<N; i++){
dis0[i] = getDistance(0,i);
if(small > dis0[i]){
small = dis0[i];
x = i;
}
}
location[x] = first+dis0[x];
stype[x] = 2;
for(i=1; i<N; i++){
if(i == x) continue;
disx[i] = getDistance(x,i);
if(dis0[i] == dis0[x]+disx[i]) op[i] = 2;
else op[i] = 1;
}
rear = 0;
for(i=1; i<N; i++){
if(op[i] == 1){
rear++;
num[rear] = i;
}
}
sort(num+1,num+rear+1,cmp);
for(i=1; i<=rear; i++){
v = num[i];
for(j=i-1; j>=1; j--){
nv = num[j];
if(stype[nv] == 1) continue;
if(nv == k) t = tmp = getDistance(k,v);
else t = tmp-(location[k]-location[nv]);
if(dis0[nv]+t == dis0[v]){
stype[v] = 1;
location[v] = location[nv]-t;
break;
}
}
if(j == 0){
stype[v] = 2;
location[v] = first+dis0[v];
k = v;
}
}
rear = 0;
for(i=1; i<N; i++){
if(op[i] == 2){
rear++;
num[rear] = i;
}
}
sort(num+1,num+rear+1,cmp2);
for(i=1; i<=rear; i++){
v = num[i];
for(j=i-1; j>=1; j--){
nv = num[j];
if(stype[nv] == 2) continue;
if(nv == k) t = tmp = getDistance(nv,v);
else t = tmp-(location[nv]-location[k]);
if(disx[v] == disx[nv]+t){
location[v] = location[nv]+t;
stype[v] = 2;
break;
}
}
if(j == 0){
stype[v] = 1;
location[v] = location[x]-disx[v];
k = v;
}
}
//for(i=0; i<N; i++) printf("%d %d\n",stype[i],location[i]);
}
컴파일 시 표준 에러 (stderr) 메시지
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:33:31: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
location[x] = first+dis0[x];
~~~~~~^
# | 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... |