Submission #898512

# Submission time Handle Problem Language Result Execution time Memory
898512 2024-01-04T19:38:14 Z EthanKim8683 Bitaro's travel (JOI23_travel) C++17
0 / 100
3000 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
using I=int;
using Lli=long long int;
const I N=200000;
const I MAX=2e9;
const I MIN=-MAX;
I x_arr[N];
I main(){
  cin.tie(0)->sync_with_stdio(0);
  I n;cin>>n;
  for(I i=0;i<n;i++)cin>>x_arr[i];
  I q;cin>>q;
  while(q--){
    I s;cin>>s;
    auto geq=[&](I x){
      return lower_bound(x_arr,x_arr+n,x)-x_arr;
    };
    auto gtn=[&](I x){
      return upper_bound(x_arr,x_arr+n,x)-x_arr;
    };
    auto ltn=[&](I x){
      return geq(x)-1;
    };
    auto leq=[&](I x){
      return gtn(x)-1;
    };
    auto val=[&](I i){
      if(i==-1){
        return MIN;
      }
      if(i==n){
        return MAX;
      }
      return x_arr[i];
    };
    Lli res=0;
    I l1=s,r1=s,t=s;
    while(1){
      I l2=val(ltn(l1)),r2=val(gtn(r1));
      if(l2==MIN&&r2==MAX){
        break;
      }
      if(t==l1){
        if(l1-l2<=r2-l1){
          I u=val(geq(l1-(r2-l1)));
          res+=t-u;
          t=u;
          l1=u;
        }else{
          I u=val(ltn(l1+(l1-l2)));
          res+=u-t;
          t=u;
          r1=u;
        }
      }else{
        if(r1-l2<=r2-r1){
          I u=val(geq(r1-(r2-r1)));
          res+=t-u;
          t=u;
          l1=u;
        }else{
          I u=val(ltn(r1+(r1-l2)));
          res+=u-t;
          t=u;
          r1=u;
        }
      }
    }
    printf("%lli\n",res);
  }
}

Compilation message

travel.cpp: In function 'I main()':
travel.cpp:25:10: warning: variable 'leq' set but not used [-Wunused-but-set-variable]
   25 |     auto leq=[&](I x){
      |          ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 3074 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 3074 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 468 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 Execution timed out 3032 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 3074 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -