이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<algorithm>
#include "rail.h"
using namespace std;
const int MAX_N=5e3+5;
vector<pair<int,int>>leftidx;
vector<pair<int,int>>rightidx;
int lidx;
int ridx;
int n;
int L[MAX_N];
int R[MAX_N];
void findLocation(int N, int first, int location[], int stype[])
{
    n=N;
    location[0]=first;
    stype[0]=1;
    vector<pair<int,int>>v;
    for(int i=1;i<n;i++)
    {
        L[i]=getDistance(0,i);
        v.push_back({L[i],i});
    }
    sort(v.begin(),v.end());
    ridx=v[0].second;
    location[ridx]=first+L[ridx];
    stype[ridx]=2;
    v.clear();
    for(int i=0;i<n;i++)
    {
        if(i==ridx)continue;
        R[i]=getDistance(ridx,i);
        v.push_back({R[i],i});
    }
    sort(v.begin(),v.end());
    lidx=v[0].second;
    location[lidx]=location[ridx]-R[lidx];
    stype[lidx]=1;
    int minusdist=L[lidx]-2*R[lidx];
    if(lidx!=0)
    {
        for(int i=0;i<n;i++)
        {
            if(i==lidx){L[i]=0;continue;}
            if(i!=0)L[i]-=minusdist;
            else L[i]=getDistance(lidx,0);
        }
    }
    ///L, R, lidx, ridx
    for(int i=0;i<n;i++)
    {
        if(i==lidx or i==ridx)continue;
        if(L[i]>R[i])
        {
            leftidx.push_back({L[i],i});
        }
        else rightidx.push_back({R[i],i});
    }
    sort(leftidx.begin(),leftidx.end());
    sort(rightidx.begin(),rightidx.end());
    ///leftidx, rightidx
    for(int type=1;type<=2;type++)
    {
        if(type==1)
        {
            v=leftidx;
            if(v.size()==0)continue;
            int idxsam=v[0].second;
            int distsam=v[0].first;
            location[idxsam]=location[lidx]-(distsam-2*R[lidx]);
            stype[idxsam]=type;
            vector<pair<int,int>>same;
            same.push_back(v[0]);
            for(int i=1;i<v.size();i++)
            {
                bool ok=0;
                int dif;
                int id;
                for(auto [distsame,idxsame]:same)
                {
                    dif=v[i].first-distsame;
                    if(dif==getDistance(idxsame,v[i].second))
                    {
                        if(ok)while(1);
                        ok=1;
                        id=idxsame;
                        //break;
                    }
                }
                if(ok)
                {
                    location[v[i].second]=location[id]+dif;
                    stype[v[i].second]=type;
                }
                else
                {
                    location[v[i].second]=location[same.back().second]-(abs(v[i].first-same.back().first));;
                    stype[v[i].second]=type;
                    same.push_back(v[i]);
                }
            }
        }
        else
        {
            v=rightidx;
            if(v.size()==0)continue;
            int idxsam=v[0].second;
            int distsam=v[0].first;
            stype[idxsam]=type;
            location[idxsam]=location[ridx]+(distsam-2*R[lidx]);
            vector<pair<int,int>>same;
            same.push_back(v[0]);
            for(int i=1;i<v.size();i++)
            {
                bool ok=0;
                int dif;
                int id;
                for(auto [distsame,idxsame]:same)
                {
                    dif=v[i].first-distsame;
                    if(dif==getDistance(idxsame,v[i].second))
                    {
                        if(ok)while(1);
                        id=idxsame;
                        ok=1;
                        //break;
                    }
                }
                if(ok)
                {
                    location[v[i].second]=location[id]-dif;
                    stype[v[i].second]=type;
                }
                else
                {
                    location[v[i].second]=location[same.back().second]+(abs(v[i].first-same.back().first));
                    stype[v[i].second]=type;
                    same.push_back(v[i]);
                }
            }
        }
    }
}
컴파일 시 표준 에러 (stderr) 메시지
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             for(int i=1;i<v.size();i++)
      |                         ~^~~~~~~~~
rail.cpp:92:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   92 |                 for(auto [distsame,idxsame]:same)
      |                          ^
rail.cpp:130:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |             for(int i=1;i<v.size();i++)
      |                         ~^~~~~~~~~
rail.cpp:135:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  135 |                 for(auto [distsame,idxsame]:same)
      |                          ^| # | 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... |