이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "rail.h"
void findLocation(int n, int first, int location[], int stype[]){
location[0] = first;
stype[0] = 1;
if(n == 1){
return;
}
ll dist[n] = {0};
ll dist2[n] = {0};
vector<ii>arr;
f(i,1,n){
dist[i] = getDistance(0,i);
arr.pb(ii(dist[i],i));
}
sort(all(arr));
ll D = arr[0].S;
location[D] = first + arr[0].F;
stype[D] = 2;
f(i,0,n){
if(i != D){
dist2[i] = getDistance(D,i);
}
}
vector<ii>left,right;
f(i,1,n){
if(i != D){
if(dist[i] < dist2[i]){
right.pb(ii(dist[i],i));
}
else{
left.pb(ii(dist2[i],i));
}
}
}
sort(all(left));
sort(all(right));
ll last = D;
for(auto x:right){
ll A = x.F - dist[last];
ll posa = getDistance(last,x.S);
assert(posa <= A);
if(posa == A){
location[x.S] = location[last] - A;
stype[x.S] = 1;
}
else{
location[x.S] = location[last] + A;
stype[x.S] = 2;
last = x.S;
}
}
last = 0;
for(auto x:left){
ll A = x.F - dist2[last];
ll posa = getDistance(last,x.S);
assert(posa <= A);
if(posa == A){
location[x.S] = location[last] + A;
stype[x.S] = 2;
}
else{
location[x.S] = location[last] - A;
stype[x.S] = 1;
last = x.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... |