# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
891080 | 2023-12-22T07:25:57 Z | vjudge1 | Bitaro's travel (JOI23_travel) | C++17 | 340 ms | 8092 KB |
#include <bits/stdc++.h> #define ll long long #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define mpa make_pair #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define sz size() #define bc back() #define ar array #define vll vector<ll> using namespace std;/* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds;*/ template <class _T> bool chmin(_T &x, const _T &y){ if(x>y){ x=y; return true; } return false; } template <class _T> bool chmax(_T &x, const _T &y){ bool flag=false; if (x<y){ x=y;flag|=true; } return flag; } //#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll inf=2e18+7; const ll mod=1e9+7; const ll N=2e5+7; const ld eps=1e-9; void solve(){ ll i,j; ll n,m; ll b; cin>>n; vector<ll> v(n); for(i=0;i<n;i++) cin>>v[i]; cin>>m; for(i=0;i<m;i++){ cin>>b; if(n==1){ cout<<abs(b-v[0])<<endl; continue; } ll sum=0; ll l,r=lb(all(v),b)-v.begin(); l=r-1; bool flag=true; if(abs(v[l]-b)<=abs(v[r]-b)) sum=abs(v[l]-b); else {sum=abs(v[r]-b);flag=false;} for(j=0;j<=35;j++){ if(l==-1 && r==n)break; if(flag){ if(r==n){ sum+=v[l]-v[0]; l=-1; continue; } if(l==0){ sum+=v[r]-v[l]; l=-1; flag=false; continue; } ll nl=ub(all(v),v[l]-(v[r]-v[l]))-v.begin()-1; if(nl<0)nl++; if(v[nl+1]-v[nl]>v[r]-v[nl+1]){ flag=false; sum+=v[r]-v[nl+1]+v[l]-v[nl+1]; l=nl; }else{ sum+=v[l]-v[nl]; l=nl; } }else{ if(l==-1){ sum+=v[n-1]-v[r]; r=n; continue; } if(r==n-1){ sum+=v[r]-v[l]; r=n; flag=true; continue; } ll nr=lb(all(v),v[r]+(v[r]-v[l]))-v.begin(); if(nr==n)nr--; if(v[nr]-v[nr-1]>=v[nr-1]-v[l]){ flag=true; sum+=v[nr-1]-v[r]+v[nr-1]-v[l]; r=nr; }else{ sum+=v[nr]-v[r]; r=nr; } } } cout<<sum<<endl; } } signed main(){ start(); ll t=1; //cin>>t; while(t--) solve(); return 0; } /* 1 7 1 2 2 3 3 4 4 5 3 6 6 7 2 4 1 5 7 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
17 | Correct | 15 ms | 1884 KB | Output is correct |
18 | Correct | 14 ms | 1884 KB | Output is correct |
19 | Correct | 15 ms | 1884 KB | Output is correct |
20 | Correct | 19 ms | 1884 KB | Output is correct |
21 | Correct | 14 ms | 1884 KB | Output is correct |
22 | Correct | 15 ms | 1884 KB | Output is correct |
23 | Correct | 15 ms | 1884 KB | Output is correct |
24 | Correct | 15 ms | 1884 KB | Output is correct |
25 | Correct | 14 ms | 1884 KB | Output is correct |
26 | Correct | 15 ms | 1884 KB | Output is correct |
27 | Correct | 14 ms | 1884 KB | Output is correct |
28 | Correct | 15 ms | 1884 KB | Output is correct |
29 | Correct | 15 ms | 1884 KB | Output is correct |
30 | Correct | 14 ms | 1884 KB | Output is correct |
31 | Correct | 15 ms | 1884 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 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 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 339 ms | 3448 KB | Output is correct |
8 | Correct | 336 ms | 3408 KB | Output is correct |
9 | Correct | 340 ms | 3364 KB | Output is correct |
10 | Correct | 337 ms | 3408 KB | Output is correct |
11 | Correct | 336 ms | 3480 KB | Output is correct |
12 | Correct | 336 ms | 3232 KB | Output is correct |
13 | Correct | 29 ms | 2280 KB | Output is correct |
14 | Correct | 21 ms | 860 KB | Output is correct |
15 | Correct | 219 ms | 3668 KB | Output is correct |
16 | Correct | 221 ms | 6992 KB | Output is correct |
17 | Correct | 220 ms | 6780 KB | Output is correct |
18 | Correct | 29 ms | 4084 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
17 | Correct | 15 ms | 1884 KB | Output is correct |
18 | Correct | 14 ms | 1884 KB | Output is correct |
19 | Correct | 15 ms | 1884 KB | Output is correct |
20 | Correct | 19 ms | 1884 KB | Output is correct |
21 | Correct | 14 ms | 1884 KB | Output is correct |
22 | Correct | 15 ms | 1884 KB | Output is correct |
23 | Correct | 15 ms | 1884 KB | Output is correct |
24 | Correct | 15 ms | 1884 KB | Output is correct |
25 | Correct | 14 ms | 1884 KB | Output is correct |
26 | Correct | 15 ms | 1884 KB | Output is correct |
27 | Correct | 14 ms | 1884 KB | Output is correct |
28 | Correct | 15 ms | 1884 KB | Output is correct |
29 | Correct | 15 ms | 1884 KB | Output is correct |
30 | Correct | 14 ms | 1884 KB | Output is correct |
31 | Correct | 15 ms | 1884 KB | Output is correct |
32 | Correct | 0 ms | 348 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 0 ms | 348 KB | Output is correct |
37 | Correct | 0 ms | 348 KB | Output is correct |
38 | Correct | 339 ms | 3448 KB | Output is correct |
39 | Correct | 336 ms | 3408 KB | Output is correct |
40 | Correct | 340 ms | 3364 KB | Output is correct |
41 | Correct | 337 ms | 3408 KB | Output is correct |
42 | Correct | 336 ms | 3480 KB | Output is correct |
43 | Correct | 336 ms | 3232 KB | Output is correct |
44 | Correct | 29 ms | 2280 KB | Output is correct |
45 | Correct | 21 ms | 860 KB | Output is correct |
46 | Correct | 219 ms | 3668 KB | Output is correct |
47 | Correct | 221 ms | 6992 KB | Output is correct |
48 | Correct | 220 ms | 6780 KB | Output is correct |
49 | Correct | 29 ms | 4084 KB | Output is correct |
50 | Correct | 282 ms | 8092 KB | Output is correct |
51 | Correct | 234 ms | 7856 KB | Output is correct |
52 | Incorrect | 228 ms | 8020 KB | Output isn't correct |
53 | Halted | 0 ms | 0 KB | - |