Submission #796444

# Submission time Handle Problem Language Result Execution time Memory
796444 2023-07-28T11:45:47 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
0 / 100
3000 ms 5888 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;
                    (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';
    }
}

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 324 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 1 ms 340 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 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 684 ms 5752 KB Output is correct
8 Correct 670 ms 5888 KB Output is correct
9 Correct 614 ms 5864 KB Output is correct
10 Correct 689 ms 5716 KB Output is correct
11 Correct 698 ms 5736 KB Output is correct
12 Correct 540 ms 5704 KB Output is correct
13 Correct 32 ms 4160 KB Output is correct
14 Correct 25 ms 1504 KB Output is correct
15 Execution timed out 3065 ms 3720 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -