이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll MOD = 1000000007;
const ll MAX = 2147483647;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll ifloor(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a < 0) return (a - b + 1) / b;
else return a / b;
}
ll iceil(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a > 0) return (a + b - 1) / b;
else return a / b;
}
void findLocation(int n, int first, int location[], int stype[]){
vector<int> pos(n, -1), dir(n);
pos[0] = first;
dir[0] = 1;
vector<int> coor(1000000);
coor[first] = 1;
vector<int> d0(n), dr(n), dl(n);
for(int i = 1; i < n; i++){
d0[i] = getDistance(0, i);
}
int rv = min_element(d0.begin() + 1, d0.end()) - d0.begin();
pos[rv] = pos[0] + d0[rv];
dir[rv] = -1;
coor[pos[rv]] = -1;
for(int i = 0; i < n; i++){
if(i == rv) continue;
dr[i] = getDistance(rv, i);
}
int lv = 0;
for(int i = 1; i < n; i++){
if(i == rv) continue;
if(dr[i] < dr[lv]) lv = i;
}
pos[lv] = pos[rv] - dr[lv];
dir[lv] = 1;
coor[pos[lv]] = 1;
// pos[0] <= pos[lv] < pos[rv]
// down down down none up
dl[0] = getDistance(lv, 0);
for(int i = 1; i < n; i++){
dl[i] = d0[i] - (pos[lv] - pos[0]);
//dl[i] = getDistance(lv, i);
}
vector<int> left, right;
for(int i = 0; i < n; i++){
if(i == lv || i == rv) continue;
if(dl[i] < dr[i]) right.eb(i);
else left.eb(i);
}
// right
int lst = rv;
sort(iter(right), [&](int x, int y){ return dl[x] < dl[y]; });
for(int i : right){
int dlst = getDistance(lst, i);
int tu = pos[lst] - dlst;
int td = pos[lv] + dl[i];
// check u (to down)
bool uok = [&](){
if(tu <= pos[lv]) return false;
int tmp = tu - pos[lv];
if((dl[i] - tmp) % 2) return false;
int x = (dl[i] - tmp) / 2;
int road = pos[lv] + tmp + x;
if(coor[road] != -1) return false;
return true;
}();
if(!uok){
pos[i] = td;
dir[i] = -1;
coor[pos[i]] = -1;
lst = i;
}
else{
pos[i] = tu;
dir[i] = 1;
coor[pos[i]] = 1;
}
}
// left
sort(iter(left), [&](int x, int y){ return dr[x] < dr[y]; });
lst = rv;
for(int i : left){
int dlst = getDistance(lst, i);
int tu = pos[rv] - dr[i];
int td = pos[lst] + dlst;
bool dok = [&](){
if(td <= lst) return false;
int tmp = pos[rv] - td;
if((dr[i] - tmp) % 2) return false;
int x = (dr[i] - tmp) / 2;
int road = pos[rv] - tmp - x;
if(coor[road] != 1) return false;
return true;
}();
if(!dok){
pos[i] = tu;
dir[i] = 1;
coor[pos[i]] = 1;
lst = i;
}
else{
pos[i] = td;
dir[i] = -1;
coor[pos[i]] = -1;
}
}
for(int i = 0; i < n; i++){
location[i] = pos[i];
stype[i] = dir[i] == 1 ? 1 : 2;
}
}
# | 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... |