답안 #792484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792484 2023-07-25T05:38:04 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
15 / 100
3000 ms 3028 KB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n, q, x, ans, l, r;
    cin >> n;
    vector < int > a(n);
    for(auto &i : a) {
        cin >> i;
    }
    for(cin >> q; q --> 0;) {
        cin >> x;
        r = upper_bound(a.begin(), a.end(), x) - a.begin(), l = r - 1;
        ans = 0;
        for(int t = n; t --> 0;) {
            if(l < 0) {
                ans += a[r] - x;
                x = a[r];
                ++ r;
            } else if(r == n) {
                ans += x - a[l];
                x = a[l];
                -- l;
            } else {
                if(x - a[l] <= a[r] - x) {
                    ans += x - a[l];
                    x = a[l];
                    -- l;
                } else {
                    ans += a[r] - x;
                    x = a[r];
                    ++ r;
                }
            }
        }
        cout << ans << '\n';
    }

}

Compilation message

travel.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 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 3008 KB Output is correct
18 Correct 21 ms 3012 KB Output is correct
19 Correct 16 ms 3028 KB Output is correct
20 Correct 20 ms 3012 KB Output is correct
21 Correct 16 ms 3012 KB Output is correct
22 Correct 16 ms 3020 KB Output is correct
23 Correct 16 ms 3020 KB Output is correct
24 Correct 17 ms 3016 KB Output is correct
25 Correct 16 ms 3028 KB Output is correct
26 Correct 16 ms 3016 KB Output is correct
27 Correct 17 ms 3028 KB Output is correct
28 Correct 16 ms 3020 KB Output is correct
29 Correct 15 ms 2892 KB Output is correct
30 Correct 15 ms 2900 KB Output is correct
31 Correct 19 ms 2892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Execution timed out 3045 ms 2696 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 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 3008 KB Output is correct
18 Correct 21 ms 3012 KB Output is correct
19 Correct 16 ms 3028 KB Output is correct
20 Correct 20 ms 3012 KB Output is correct
21 Correct 16 ms 3012 KB Output is correct
22 Correct 16 ms 3020 KB Output is correct
23 Correct 16 ms 3020 KB Output is correct
24 Correct 17 ms 3016 KB Output is correct
25 Correct 16 ms 3028 KB Output is correct
26 Correct 16 ms 3016 KB Output is correct
27 Correct 17 ms 3028 KB Output is correct
28 Correct 16 ms 3020 KB Output is correct
29 Correct 15 ms 2892 KB Output is correct
30 Correct 15 ms 2900 KB Output is correct
31 Correct 19 ms 2892 KB Output is correct
32 Correct 1 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 1 ms 320 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Execution timed out 3045 ms 2696 KB Time limit exceeded
39 Halted 0 ms 0 KB -