Submission #796580

# Submission time Handle Problem Language Result Execution time Memory
796580 2023-07-28T14:16:47 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
0 / 100
1 ms 340 KB
#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;
                    (a[m] - s < s - 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[cr_r] - s < s - a[l] ? l : r) = m;
                }
                ans += s - a[r];
                s = a[r];
                cr_l = l;
            }
        }
        cout << ans + a[n - 1] - a[0] << '\n';
    }
}

Compilation message

travel.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -