이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shortcut.h"
#include "bits/stdc++.h"
#define ff first
#define ss second
#define ll long long
using namespace std;
typedef pair<ll, ll> pll;
//x+y, y-x (45 degrees rotation)
//|x-xx|+|y-yy| -> max(|x-xx|, |y-yy|)
const ll INF = 1e18;
const ll N = 1e6+6;
vector<ll> id;
int sz;
int get_id(ll x){
return 1 + int(lower_bound(id.begin(), id.end(), x) - id.begin());
}
struct node{
ll x, y, xx, yy;
node(){}
node(ll _x, ll _y, ll _xx, ll _yy){
x = _x; y = _y; yy = _yy; xx = _xx;
}
}F[N];
node merge(node a, node b){
return node(max(a.x, b.x), max(a.y, b.y), min(a.xx, b.xx), min(a.yy, b.yy));
}
node get(int x){
node ans = node(-INF, -INF, INF, INF);
for (; x <= sz; x += x&(-x))
ans = merge(ans, F[x]);
return ans;
}
void upd(int x, node v){
for (;x;x -= x&(-x))
F[x] = merge(F[x], v);
}
bool check(ll k, vector<int> &d, int c, vector<ll>&p){
for (int i = 0; i <= sz; i++)
F[i] = node(-INF, -INF, INF, INF);
int n = d.size();
ll X = -INF, Y = -INF;
ll XX = INF, YY = INF;
for (int j = 0; j < n; j++){
int b = get_id(-d[j] - p[j]+k+1);
node value = get(b);
X = max(X, value.x + p[j] -k + c + d[j]);
Y = max(Y, value.y + p[j] -k + c + d[j]);
XX = min(XX, value.xx + p[j] + k - c - d[j]);
YY = min(YY, value.yy + p[j] + k - c - d[j]);
int i = j;
int a = get_id(d[i] - p[i]);
upd(a, node(p[i] + d[i], -p[i] + d[i], p[i] - d[i], -p[i] - d[i]));
}
if (X > XX or Y > YY)
return 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (X - p[j] <= p[i] and p[i] <= XX - p[j] and -Y + p[j] >= p[i] and p[i] >= -YY + p[j])
return 1;
return 0;
}
ll find_shortcut(int n, vector<int> l, vector<int> d, int c){
vector<ll> p(n);
for (int i = 0; i < n-1; i++)
p[i+1] = p[i] + l[i];
for (int j = 0; j < n; j++)
id.push_back(d[j] - p[j]);
sort(id.begin(), id.end());
id.erase(unique(id.begin(), id.end()), id.end());
sz = id.size();
ll st = 0, en = INF;
while (st < en){
ll mid = (st+en) >> 1;
if (check(mid, d, c, p))
en = mid;
else
st = mid + 1;
}
return st;
}
# | 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... |
# | 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... |