이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<ii> vii;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define RE1(a,b) REP(a,1,b+1)
#define FOR(a,b) for(auto& a : b)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(),a.end()
const int MX = 6000;
void findLocation(int n, int first, int location[], int stype[]) {
auto getD = [](int u, int v) {
static int mem[MX][MX];
if(u == v) return 0;
if(mem[u][v] != 0)
return mem[u][v];
return mem[u][v] = mem[v][u] = getDistance(u,v);
};
int closest = 1e9;
REP(i,1,n)
closest = min(closest, getD(0,i));
int u = -1;
REP(i,1,n)
if(getD(0,i) == closest)
u = i;
stype [0] = 1;
location[0] = first;
stype [u] = 2;
location[u] = first + getD(0,u);
vii pq;
REP(i,1,n) {
if(i == u) continue;
int a = getD(i,0);
pq.pb({a,i});
}
sort(all(pq));
int L=0, R=u;
FOR(p,pq) {
int i=p.se;
int dli = getD(L,i);
int dri = getD(R,i);
int d0i = getD(0,i);
bool possible;
int posl = location[R] - dri;
int posr = location[L] + dli;
int expected = 0;
// case: ( ( ) )
// L 0 R i
possible = true;
if(posr <= location[R])
possible = false;
if(posr != location[0] + d0i)
possible = false;
if(possible) {
stype[i] = 2;
location[i] = posr;
R = i;
continue;
}
// case: ( ) ( )
// L i 0 R
possible = true;
if(posr >= location[0])
possible = false;
expected = 1e9;
int mnRight = 1e9;
RE(j,n)
if(stype[j] == 2)
if(location[j] > location[0])
mnRight = min(mnRight, location[j]);
RE(j,n)
if(stype[j] == 1)
if(location[j] < posr)
expected = min(expected, abs(location[j]-posr) + abs(mnRight-location[j]) + abs(mnRight-location[0]));
if(d0i != expected)
possible = false;
expected = 1e9;
RE(j,n)
if(stype[j] == 1)
if(location[j] < posr)
expected = min(expected, abs(location[j]-posr) + abs(location[j]-location[R]));
if(dri != expected)
possible = false;
if(possible) {
stype[i] = 2;
location[i] = posr;
continue;
}
stype[i] = 1;
location[i] = posl;
if(location[i] < location[L])
L = i;
}
}
# | 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... |