Submission #890870

# Submission time Handle Problem Language Result Execution time Memory
890870 2023-12-22T04:33:15 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
0 / 100
102 ms 8528 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector <int> X(n);
    for ( auto &u: X ) cin >> u;
    int q; cin >> q;
    vector <int> S(q);
    for ( auto &u: S ) cin >> u;
    if ( false && q == 1 ){
        int x = S[0];
        const int inf = 1e15;
        set <int> st{-inf, inf};
        for ( int i = 0; i < n; i++ ){
            st.insert(X[i]);
        }
        int ans = 0;
        while ( st.size() > 2 ){
            auto it = st.lower_bound(x);
            assert(*prev(it) <= x && *it >= x);
            if ( abs(*prev(it) - x) <= abs(*it - x) ){
                ans += x - *prev(it);
                x = *prev(it);
                st.erase(prev(it));
            } else{
                ans += -x + *it;
                x = *it;
                st.erase(it);
            }
        }
        cout << ans << ln;
        return 0;
    }
    for ( auto &xx: S ){
        int it = lower_bound(all(X), xx) - X.begin();
        if ( it - 1 >= 0 && (it == n || X[it] - xx >= xx - X[it - 1]) ) --it;
        int ans = abs(X[it] - xx), l = it - 1, r = it + 1, x = X[it];
        while ( l >= 0 || r < n ){
            if ( l < 0 ){
                ans += abs(X.back() - x);
                break;
            } else if ( r >= n ){
                ans += abs(X[0] - x);
                break;
            } else{
                if ( abs(X[r] - x) >= 100 ){
                    ans += abs(X[0] - x);
                    x = X[0]; l = -1;
                    continue;
                }
                if ( abs(X[l] - x) > 100 ){
                    ans += abs(X.back() - x);
                    x = X.back(); r = n;
                    continue;
                }
                if ( abs(X[l] - x) <= abs(X[r] - x) ){
                    ans += abs(X[l] - x);
                    x = X[l--];
                } else{
                    ans += abs(X[r] - x);
                    x = X[r++];
                }
            }
        }
        cout << ans << ln;
    }

    cout << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 93 ms 7500 KB Output is correct
8 Correct 88 ms 7440 KB Output is correct
9 Correct 96 ms 7504 KB Output is correct
10 Correct 91 ms 7384 KB Output is correct
11 Correct 102 ms 7508 KB Output is correct
12 Correct 90 ms 7388 KB Output is correct
13 Correct 33 ms 5892 KB Output is correct
14 Correct 23 ms 3152 KB Output is correct
15 Incorrect 65 ms 8528 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -