이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "rail.h"
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
using namespace std;
void findLocation(int N, int first, int location[], int stype[])
{
int lid = 0, rid = -1;
vector<int> dist(N, 0);
for(int i = 0; i < N; i ++){
if(i == lid)continue;
int temp = getDistance(lid, i);
dist[i] = temp;
}
vector<int> order(N);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int a, int b){return dist[a] < dist[b];});
int d = dist[order[1]];
rid = order[1];
lid = order[0];
int cr = lid, cl = rid;
stype[order[0]] = 1;
stype[order[1]] = 2;
location[order[0]] = first;
location[order[1]] = first + d;
for(int i : order){
if(stype[i])continue;
int t1 = getDistance(lid, i);
int t2 = getDistance(rid, i);
int x = location[rid] - location[cr], xx = location[cl]-location[lid];
//cout << i << " " << t1 << " " << t2 << " " << d << " " << lid << " " << rid << endl;
if(t1 == t2 - 2 * x + d){
stype[i] = 2;
d = t1;
location[i] = location[lid] + d;
rid = i;
}
//else if(t2 < d){
//stype[i] = 1;
//location[i] = location[rid] - t2;
//}
else if(t2 > d){
stype[i] = 1;
location[i] = location[rid] - t2;
d = t2;
lid = i;
}
}
//for(int i = 0; i < N; i ++) cout << location[i] << " ";
//cout << endl;
//for(int i = 0; i < N; i ++)cout << stype[i] << " ";
//cout << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:37:47: warning: unused variable 'xx' [-Wunused-variable]
37 | int x = location[rid] - location[cr], xx = location[cl]-location[lid];
| ^~
# | 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... |