Submission #792431

# Submission time Handle Problem Language Result Execution time Memory
792431 2023-07-25T04:48:08 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
15 / 100
3000 ms 3028 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

ll INF = 1e9 + 10;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int x[n + 2] = {};
    for(int i = 1; i <= n; i++) 
        cin >> x[i];
    int q;
    cin >> q;
    while(q--) {
        ll ans = 0;
        ll cur;
        cin >> cur;
        int cnt = 0;
        int l = 0, r = 1;
        while(r <= n && x[r] <= cur) r++;
        l = r - 1;
        while(cnt < n) {
            // cout << l << ' ' << r << '\n';
            int w1 = (l > 0 ? cur - x[l] : INF);
            int w2 = (r < n + 1 ? x[r] - cur : INF);
            ans += min(w1, w2);
            if(w1 <= w2) cur = x[l--];
            else cur = x[r++];
            cnt++;
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 16 ms 3020 KB Output is correct
18 Correct 16 ms 3012 KB Output is correct
19 Correct 16 ms 2988 KB Output is correct
20 Correct 16 ms 2996 KB Output is correct
21 Correct 16 ms 3020 KB Output is correct
22 Correct 16 ms 2988 KB Output is correct
23 Correct 16 ms 3020 KB Output is correct
24 Correct 16 ms 3028 KB Output is correct
25 Correct 16 ms 3000 KB Output is correct
26 Correct 16 ms 3020 KB Output is correct
27 Correct 16 ms 3008 KB Output is correct
28 Correct 15 ms 3004 KB Output is correct
29 Correct 15 ms 2900 KB Output is correct
30 Correct 15 ms 2880 KB Output is correct
31 Correct 15 ms 2888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Execution timed out 3057 ms 2668 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 16 ms 3020 KB Output is correct
18 Correct 16 ms 3012 KB Output is correct
19 Correct 16 ms 2988 KB Output is correct
20 Correct 16 ms 2996 KB Output is correct
21 Correct 16 ms 3020 KB Output is correct
22 Correct 16 ms 2988 KB Output is correct
23 Correct 16 ms 3020 KB Output is correct
24 Correct 16 ms 3028 KB Output is correct
25 Correct 16 ms 3000 KB Output is correct
26 Correct 16 ms 3020 KB Output is correct
27 Correct 16 ms 3008 KB Output is correct
28 Correct 15 ms 3004 KB Output is correct
29 Correct 15 ms 2900 KB Output is correct
30 Correct 15 ms 2880 KB Output is correct
31 Correct 15 ms 2888 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Execution timed out 3057 ms 2668 KB Time limit exceeded
39 Halted 0 ms 0 KB -