이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
void findLocation(int N, int first, int location[], int stype[])
{
vvi dist(5002,vi(5002,0));
FOR(i,0,N)location[i] = -1;
location[0] = first;
stype[0] = 1;
if(N==1)return;
FOR(i,0,N){
FOR(j,i+1,N){
dist[i][j] = getDistance(i,j);
dist[j][i] = dist[i][j];
}
}
int min_pos = 0, min_dis = -1;
FOR(i,1,N){
if(min_dis == -1 || dist[0][i] < min_dis){
min_dis = dist[0][i];
min_pos = i;
}
}
location[min_pos] = min_dis + location[0];
stype[min_pos] = 2;
priority_queue<pi> right,left;
FOR(i,1,N){
if(i == min_pos)continue;
if(dist[0][i] < dist[min_pos][i]){
right.push({-dist[0][i],i});
}else{
left.push({-dist[1][i],i});
}
}
set<pi> rightU,leftD;
while(!right.empty()){
pi a = right.top();right.pop();
a.F *= -1;
int downID = -1;
for(pi b:rightU){
if(b.F<a.F){
downID = b.S;
}
}
if(downID != -1){
if(dist[downID][a.S] < dist[0][a.S]){
stype[a.S] = 1;
location[a.S] = location[downID] - dist[downID][a.S];
}
}
if(location[a.S] == -1){
stype[a.S] = 2;
location[a.S] = dist[0][a.S] + location[0];
rightU.insert({dist[0][a.S],a.S});
}
}
while(!left.empty()){
pi a = left.top();left.pop();
a.F *= -1;
int upID = -1;
for(pi b:leftD){
if(b.F<a.F){
upID = b.S;
}
}
if(upID != -1){
if(dist[upID][a.S] < dist[min_pos][a.S]){
stype[a.S] = 2;
location[a.S] = location[upID] + dist[upID][a.S];
}
}
if(location[a.S] == -1){
stype[a.S] = 1;
location[a.S] = - dist[min_pos][a.S] + location[min_pos];
leftD.insert({dist[min_pos][a.S],a.S});
}
}
}
# | 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... |