답안 #796017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796017 2023-07-28T04:19:27 Z 반딧불(#10068) Bitaro's travel (JOI23_travel) C++17
15 / 100
3000 ms 4332 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct segTree{
    int tree[800002];

    void init(int i, int l, int r, int* v){
        if(l==r){
            tree[i] = v[l];
            return;
        }
        int m = (l+r)>>1;
        init(i*2, l, m, v);
        init(i*2+1, m+1, r, v);
        tree[i] = max(tree[i*2], tree[i*2+1]);
    }

    int findRight(int i, int l, int r, int x, int lim){ /// lim �̻��� �� ã��
        if(r<x || tree[i] < lim) return r+1;
        if(l==r) return l;
        int m = (l+r)>>1;
        int tmp = findRight(i*2, l, m, x, lim);
        if(tmp == m+1) return findRight(i*2+1, m+1, r, x, lim);
        else return tmp;
    }

    int findLeft(int i, int l, int r, int x, int lim){
        if(x<l || tree[i] < lim) return l-1;
        if(l==r) return l;
        int m = (l+r)>>1;
        int tmp = findLeft(i*2+1, m+1, r, x, lim);
        if(tmp == m) return findLeft(i*2, l, m, x, lim);
        else return tmp;
    }
} tree;

int n, q;
int arr[200002];
int diff[200002];

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
    for(int i=1; i<n; i++) diff[i] = arr[i+1] - arr[i];
    if(n!=1) tree.init(1, 1, n-1, diff);
    scanf("%d", &q);

    while(q--){
        int start;
        ll ans = 0;
        scanf("%d", &start);
        int idx = lower_bound(arr+1, arr+n+1, start) - arr;

        if(idx == n+1) ans = start - arr[n], start = n;
        else if(idx == 1) ans = arr[1] - start, start = 1;
        else if(arr[idx] - start >= start - arr[idx-1]) ans = start - arr[idx-1], start = idx-1;
        else ans = arr[idx] - start, start = idx;

        int s = start, e = start, x = start;
        while(1<s || e<n){
            if(s==1) ans += arr[n] - arr[x], e = n;
            else if(e==n) ans += arr[x] - arr[1], s = 1;
            else{
                if(arr[x] - arr[s-1] <= arr[e+1] - arr[x]) ans += arr[x] - arr[s-1], s--, x=s;
                else ans += arr[e+1] - arr[x], e++, x=e;
            }
        }

        printf("%lld\n", ans);
    }
}

Compilation message

travel.cpp: In function 'int main()':
travel.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
travel.cpp:46:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~
travel.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
travel.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf("%d", &start);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 0 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 17 ms 3924 KB Output is correct
18 Correct 20 ms 3884 KB Output is correct
19 Correct 17 ms 3876 KB Output is correct
20 Correct 17 ms 3856 KB Output is correct
21 Correct 17 ms 3912 KB Output is correct
22 Correct 17 ms 3824 KB Output is correct
23 Correct 18 ms 3924 KB Output is correct
24 Correct 26 ms 3900 KB Output is correct
25 Correct 20 ms 3876 KB Output is correct
26 Correct 17 ms 3900 KB Output is correct
27 Correct 17 ms 3804 KB Output is correct
28 Correct 17 ms 3908 KB Output is correct
29 Correct 17 ms 3908 KB Output is correct
30 Correct 17 ms 3900 KB Output is correct
31 Correct 17 ms 3840 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Execution timed out 3071 ms 4332 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 17 ms 3924 KB Output is correct
18 Correct 20 ms 3884 KB Output is correct
19 Correct 17 ms 3876 KB Output is correct
20 Correct 17 ms 3856 KB Output is correct
21 Correct 17 ms 3912 KB Output is correct
22 Correct 17 ms 3824 KB Output is correct
23 Correct 18 ms 3924 KB Output is correct
24 Correct 26 ms 3900 KB Output is correct
25 Correct 20 ms 3876 KB Output is correct
26 Correct 17 ms 3900 KB Output is correct
27 Correct 17 ms 3804 KB Output is correct
28 Correct 17 ms 3908 KB Output is correct
29 Correct 17 ms 3908 KB Output is correct
30 Correct 17 ms 3900 KB Output is correct
31 Correct 17 ms 3840 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 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Execution timed out 3071 ms 4332 KB Time limit exceeded
39 Halted 0 ms 0 KB -