이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
using ll = long long;
ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
vector<ll> x(n, 0);
for (int i = 0; i + 1 < n; i++) {
x[i + 1] = x[i] + (ll)l[i];
}
auto good = [&](ll k) {
ll min_x = LLONG_MIN, max_x = LLONG_MAX, min_y = LLONG_MIN, max_y = LLONG_MAX;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if ((ll)d[i] + (ll)d[j] + x[j] - x[i] > k) {
ll v = k - (ll)c - (ll)d[i] - (ll)d[j];
pair<ll, ll> lower_left = mp(x[i] - v - x[j], x[i] - v + x[j]);
pair<ll, ll> upper_right = mp(x[i] + v - x[j], x[i] + v + x[j]);
min_x = max(min_x, lower_left.first);
max_x = min(max_x, upper_right.first);
min_y = max(min_y, lower_left.second);
max_y = min(max_y, upper_right.second);
}
}
}
if (min_x <= max_x && min_y <= max_y) {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (min_x <= x[i] - x[j] && x[i] - x[j] <= max_x && min_y <= x[i] + x[j] && x[i] + x[j] <= max_y) {
return true;
}
}
}
return false;
} else {
return false;
}
};
ll lo = 0, hi = (ll)1e16, ans = -1;
while (lo <= hi) {
ll mid = (lo + hi) / 2ll;
if (good(mid)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
# | 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... |