Submission #890822

# Submission time Handle Problem Language Result Execution time Memory
890822 2023-12-22T03:51:55 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
15 / 100
114 ms 10128 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);
    int n;
    cin>>n;
    set <int> st;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        st.insert(x);
    }
    int q;
    cin>>q;
    while(q--){
        int x;
        cin>>x;
        int ans=0;
        int next=x;
        bool flag=0;
        
        auto it=st.lower_bound(x);
        if(it!=st.end() && *it==x)flag=1;
        
        if(!flag){
            int mn=1e18;
            int cur=x;
            if(it!=st.begin()){
                it--;
                mn=min(mn,abs(cur-*it));
                next=*it;
                it++;
            }
            if(it!=st.end()){
                if(abs(cur-*it)<mn){
                    mn=abs(cur-*it);
                    next=*it;
                }
            }
            if(mn!=1e18)ans+=mn;
        }
        //cout<<ans<<" "<<next<<"\n";
        while(!st.empty()){
            //cout<<ans<<" "<<next<<"\n";
            auto it=st.lower_bound(next);
            int mn=1e18;
            int cur=*it;
            if(it!=st.begin()){
                it--;
                mn=min(mn,abs(cur-*it));
                next=*it;
                it++;
            }
            it++;
            if(it!=st.end()){
                if(abs(cur-*it)<mn){
                    mn=abs(cur-*it);
                    next=*it;
                }
            }
            it--;
            if(mn!=1e18)ans+=mn;
            st.erase(it);
        }
        cout<<ans<<"\n";
    }
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 97 ms 9800 KB Output is correct
18 Correct 108 ms 9756 KB Output is correct
19 Correct 97 ms 9808 KB Output is correct
20 Correct 98 ms 9604 KB Output is correct
21 Correct 99 ms 9608 KB Output is correct
22 Correct 110 ms 9556 KB Output is correct
23 Correct 97 ms 9680 KB Output is correct
24 Correct 99 ms 9556 KB Output is correct
25 Correct 107 ms 9556 KB Output is correct
26 Correct 114 ms 9808 KB Output is correct
27 Correct 106 ms 9808 KB Output is correct
28 Correct 103 ms 9716 KB Output is correct
29 Correct 99 ms 9556 KB Output is correct
30 Correct 100 ms 9800 KB Output is correct
31 Correct 106 ms 10128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 97 ms 9800 KB Output is correct
18 Correct 108 ms 9756 KB Output is correct
19 Correct 97 ms 9808 KB Output is correct
20 Correct 98 ms 9604 KB Output is correct
21 Correct 99 ms 9608 KB Output is correct
22 Correct 110 ms 9556 KB Output is correct
23 Correct 97 ms 9680 KB Output is correct
24 Correct 99 ms 9556 KB Output is correct
25 Correct 107 ms 9556 KB Output is correct
26 Correct 114 ms 9808 KB Output is correct
27 Correct 106 ms 9808 KB Output is correct
28 Correct 103 ms 9716 KB Output is correct
29 Correct 99 ms 9556 KB Output is correct
30 Correct 100 ms 9800 KB Output is correct
31 Correct 106 ms 10128 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Incorrect 0 ms 348 KB Output isn't correct
34 Halted 0 ms 0 KB -