이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 200200;
long long a[N];
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q, s, l, r, m, cr_l, cr_r, ans;
cin >> n;
for(int i = 0; i < n; ++ i) {
cin >> a[i];
}
for(cin >> q; q --> 0;) {
cin >> s;
cr_l = -1, cr_r = n;
ans = 0;
for(; cr_l + 1 < cr_r;) {
m = (cr_l + cr_r) / 2;
(a[m] > s ? cr_r : cr_l) = m;
}
for(; cr_l != -1 && cr_r != n;) {
if(s - a[cr_l] > a[cr_r] - s) {
l = cr_r, r = n;
for(; l + 1 < r;) {
m = (l + r) / 2;
(2 * a[m] < a[m - 1] - a[cr_l] ? l : r) = m;
}
ans += a[l] - s;
s = a[l];
cr_r = r;
} else {
l = -1, r = cr_l;
for(; l + 1 < r;) {
m = (l + r) / 2;
(a[r] + a[m] < 2 * a[m + 1] ? l : r) = m;
}
ans += s - a[r];
s = a[r];
cr_l = l;
}
}
if(cr_r != n) {
ans += a[n - 1] - s;
} else if(cr_l != -1) {
ans += s - a[0];
}
cout << ans << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
travel.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main() {
| ^~~~
# | 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... |