Submission #1015607

# Submission time Handle Problem Language Result Execution time Memory
1015607 2024-07-06T15:10:18 Z onbert Bitaro's travel (JOI23_travel) C++17
15 / 100
3000 ms 13324 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    int a[n+2];
    for (int i=1;i<=n;i++) cin >> a[i];
    set<int> s;
    int q;
    cin >> q;
    while (q--) {
        for (int i=1;i<=n;i++) s.insert(a[i]);
        s.insert(-INF); s.insert(INF);
        int x;
        cin >> x;
        int ans = 0, cnt = 0;
        bool right = true;
        while (s.size() > 2) {
            int l = *prev(s.lower_bound(x));
            int r = *s.lower_bound(x);
            if (abs(x-l) <= abs(r-x)) {
                if (right) cnt++;
                ans += abs(x-l);
                x = l;
                s.erase(l);
                right = false;
            } else {
                if (!right) cnt++;
                ans += abs(r-x);
                x = r;
                s.erase(r);
                right = true;
            }
        }
        cout << ans << endl;
        assert(cnt <= 32);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 468 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 360 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 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 468 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 360 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 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 58 ms 13140 KB Output is correct
18 Correct 72 ms 13252 KB Output is correct
19 Correct 58 ms 13120 KB Output is correct
20 Correct 60 ms 13140 KB Output is correct
21 Correct 66 ms 13252 KB Output is correct
22 Correct 69 ms 13140 KB Output is correct
23 Correct 57 ms 13136 KB Output is correct
24 Correct 60 ms 13136 KB Output is correct
25 Correct 62 ms 13136 KB Output is correct
26 Correct 75 ms 13136 KB Output is correct
27 Correct 68 ms 13324 KB Output is correct
28 Correct 66 ms 13324 KB Output is correct
29 Correct 61 ms 13136 KB Output is correct
30 Correct 60 ms 13192 KB Output is correct
31 Correct 61 ms 13136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Execution timed out 3095 ms 12748 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 468 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 360 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 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 58 ms 13140 KB Output is correct
18 Correct 72 ms 13252 KB Output is correct
19 Correct 58 ms 13120 KB Output is correct
20 Correct 60 ms 13140 KB Output is correct
21 Correct 66 ms 13252 KB Output is correct
22 Correct 69 ms 13140 KB Output is correct
23 Correct 57 ms 13136 KB Output is correct
24 Correct 60 ms 13136 KB Output is correct
25 Correct 62 ms 13136 KB Output is correct
26 Correct 75 ms 13136 KB Output is correct
27 Correct 68 ms 13324 KB Output is correct
28 Correct 66 ms 13324 KB Output is correct
29 Correct 61 ms 13136 KB Output is correct
30 Correct 60 ms 13192 KB Output is correct
31 Correct 61 ms 13136 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Execution timed out 3095 ms 12748 KB Time limit exceeded
39 Halted 0 ms 0 KB -