이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
template<class T>
void readi(T &x)
{
T input = 0;
bool negative = false;
char c = ' ';
while (c < '-')
{
c = getchar();
}
if (c == '-')
{
negative = true;
c = getchar();
}
while (c >= '0')
{
input = input * 10 + (c - '0');
c = getchar();
}
if (negative)
{
input = -input;
}
x = input;
}
template<class T>
void printi(T output)
{
if (output == 0)
{
putchar('0');
return;
}
if (output < 0)
{
putchar('-');
output = -output;
}
int aout[20];
int ilen = 0;
while(output)
{
aout[ilen] = ((output % 10));
output /= 10;
ilen++;
}
for (int i = ilen - 1; i >= 0; i--)
{
putchar(aout[i] + '0');
}
return;
}
template<class T>
void ckmin(T &a, T b)
{
a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
a = max(a, b);
}
long long randomize(long long mod)
{
return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << x << endl;
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-20;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 5013
long long normalize(long long x, long long mod = INF)
{
return (((x % mod) + mod) % mod);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int N, P;
int dist[MAXN][MAXN];
int query(int x, int y)
{
if (x > y) swap(x, y);
return (x == y ? 0 : (dist[x][y] ? dist[x][y] : dist[x][y] = getDistance(x, y)));
}
void findLocation(int n, int first, int location[], int stype[])
{
N = n;
//let's say we know all the answers to 0
stype[0] = 1;
location[0] = first;
if (N == 1)
{
return;
}
int A = -1, D;
D = INF;
for (int i = 0; i < N; i++)
{
if (i == 0) continue;
int cur = query(0, i);
if (cur < D)
{
A = i;
D = cur;
}
}
stype[A] = 2;
location[A] = location[0] + D;
vector<pii> rt, lt;
for (int i = 0; i < N; i++)
{
if (i == 0 || i == A) continue;
if (query(A, i) > query(0, i))
{
//it's to the right
rt.PB({query(0, i) - D, i});
}
else if (query(A, i) < D)
{
stype[i] = 1;
location[i] = location[A] - query(A, i);
}
else
{
//it's to the left
lt.PB({query(A, i) - D, i});
}
}
sort(rt.begin(), rt.end());
int rec = A;
for (pii p : rt)
{
int idx = p.se;
if (query(0, idx) == query(0, rec) + query(rec, idx))
{
location[idx] = location[rec] - query(rec, idx);
stype[idx] = 1;
}
else
{
location[idx] = location[0] + query(0, idx);
stype[idx] = 2;
rec = idx;
}
}
sort(lt.begin(), lt.end());
rec = 0;
for (pii p : lt)
{
int idx = p.se;
if (query(A, idx) == query(A, rec) + query(rec, idx))
{
location[idx] = location[rec] + query(rec, idx);
stype[idx] = 2;
}
else
{
location[idx] = location[A] - query(A, idx);
stype[idx] = 1;
rec = idx;
}
}
// for (int i = 0; i < N; i++)
// {
// cerr << stype[i] << ' ' << location[i] << endl;
// }
//for a given 0: you can find the next 1
//1 for type C, 2 for type D, 0 for nothing!
}
/*
4 4
1 2
2 5
1 3
1 1
*/
# | 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... |