# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
915254 | vjudge1 | Shortcut (IOI16_shortcut) | C++17 | 1 ms | 600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) {
vector<int64_t> a(n), b(n); // a = x + d, b = x - d
vector<int64_t> x(n);
for (int i = 1; i < n; i++) x[i] = x[i - 1] + l[i - 1];
for (int i = 0; i < n; i++) a[i] = x[i] + d[i], b[i] = x[i] - d[i];
// abs(x[i] - x[p]) + abs(x[j] - x[q]) + d[i] + d[j] + c <= target
// x[i] - x[p] + x[j] - x[q] + d[i] + d[j] + c <= target
// x[p] - x[i] + x[j] - x[q] + d[i] + d[j] + c <= target
// x[i] - x[p] + x[q] - x[j] + d[i] + d[j] + c <= target
// x[p] - x[i] + x[q] - x[j] + d[i] + d[j] + c <= target
// x[p] + x[q] >= x[i] + x[j] + d[i] + d[j] + c - target
// x[p] + x[q] <= x[i] + x[j] - d[i] - d[j] - c + target
// x[q] - x[p] <= x[j] - x[i] - d[i] - d[j] - c + target
// x[q] - x[p] >= x[j] - x[i] + d[i] + d[j] + c - target
// k := c - target
// x[p] + x[q] >= (x[i] + d[i]) + (x[j] + d[j]) + k
// x[p] + x[q] <= (x[i] - d[i]) + (x[j] - d[j]) - k
// x[q] - x[p] >= (x[j] + d[j]) - (x[i] + d[i]) + k
// x[q] - x[p] <= (x[j] - d[j]) - (x[i] - d[i]) - k
// x[p] + x[q] >= a[i] + a[j] + k
// x[p] + x[q] <= b[i] + b[j] - k
// x[q] - x[p] >= a[j] - a[i] + k
// x[q] - x[p] <= b[j] - b[i] - k
auto check = [&](int64_t target) {
const int64_t k = c - target;
int64_t low_sum = 0, high_sum = x.back() * 2;
int64_t low_diff = 0, high_diff = x.back();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (x[j] - x[i] + d[i] + d[j] > target) {
low_sum = max(low_sum, a[i] + a[j] + k);
high_sum = min(high_sum, b[i] + b[j] - k);
low_diff = max(low_diff, a[j] - a[i] + k);
high_diff = min(high_diff, b[j] - b[i] - k);
}
}
}
if (low_sum > high_sum) return 0;
if (low_diff > high_diff) return 0;
// low_sum <= x[p] + x[q] <= high_sum
// low_diff <= x[q] - x[p] <= high_diff
for (int p = 0; p < n; p++) {
for (int q = p + 1; q < n; q++) {
if (low_sum <= x[p] + x[q] && x[p] + x[q] <= high_sum &&
low_diff <= x[q] - x[p] && x[q] - x[p] <= high_diff) {
return 1;
}
}
}
return 0;
};
int64_t low = 0, high = 1ll << 60;
while (low < high) {
int64_t mid = low + high >> 1;
if (check(mid)) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |