제출 #969094

#제출 시각아이디문제언어결과실행 시간메모리
969094dong_gasBitaro's travel (JOI23_travel)C++17
0 / 100
373 ms6964 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/extc++.h> #define all(v) v.begin(), v.end() #define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end()) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pint; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll n, q; void solve() { cin>>n; vector<ll> x(n); for(ll& xx: x) cin>>xx; cin>>q; while(q --> 0) { ll s; cin>>s; ll idx=lower_bound(all(x),s)-x.begin(), ans=0; ll l, r; if(idx==0) { cout<<x[n-1]-s<<'\n'; continue; } else if(idx==n) { cout<<s-x[0]<<'\n'; continue; } else { ll rd=x[idx]-s, ld=s-x[idx-1]; if(ld<=rd) ans+=ld, l=r=idx-1, s=x[idx-1]; else ans+=rd, l=r=idx, s=x[idx]; } //l~r까지 완료 함... while(1) { if(l==0) { ans+=x[n-1]-s; break; } if(r==n-1) { ans+=s-x[0]; break; } bool chk=false; if(l==1 && r==3) chk=true; if(s-x[l-1]<=x[r+1]-s) {//좌 ll i=lower_bound(all(x),2*s-x[r+1])-x.begin(); ans+=s-x[i]; s=x[i]; l=i; } else { ll i=lower_bound(all(x),2*s-x[l-1])-x.begin(); if(i==n) i--; //if(chk) cout<<i<<endl; ans+=x[i]-s; s=x[i]; r=i; } if(chk) { //cout<<ans<<' '<<l<<' '<<r<<' '<<s<<endl; //return; } } cout<<ans<<'\n'; } } int main() { cin.tie(0)->sync_with_stdio(0); int tc=1; //cin>>tc; while(tc--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...