# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
891079 | 2023-12-22T07:24:35 Z | vjudge1 | Bitaro's travel (JOI23_travel) | C++17 | 714 ms | 547136 KB |
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl "\n" #define ll long long #define int ll int E,B; void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll N=5e5+5,INF=1e18,mod=1e9+7; vector<vector<int>> pr(N,vector<int>(65,0)), nx(N,vector<int>(65,0)); void solve(){ int n;cin>>n; vector<int> x(n+2); for(int i=1;i<=n;i++) cin>>x[i]; x[0]=-INF; x[n+1]=INF; for(int i=0;i<=55;i++) pr[1][i]=1; for(int i=2;i<=n;i++){ pr[i]=pr[i-1]; for(int j=0;j<=55;j++){ if((1<<j)<=x[i]-x[i-1]) pr[i][j]=i; } } for(int i=0;i<=55;i++) nx[n][i]=n; for(int i=n-1;i>=1;i--){ nx[i]=nx[i+1]; for(int j=0;j<=55;j++){ if((1<<j)<=x[i+1]-x[i]) nx[i][j]=i; } } int q,l,r,ans;cin>>q; while(q--){ int a;cin>>a; int pos=upper_bound(all(x),a)-x.begin(); if(a-x[pos-1]<=x[pos]-a) pos--; ans=abs(a-x[pos]); l=r=pos; bool s=(x[pos]-x[pos-1]<=x[pos+1]-x[pos]); int k=0; while(l>1 || r<n){ while((1<<(k+1))<=(x[r]-x[l])) k++; if(s){ ans+=x[l]-x[pr[l][k]]; l=pr[l][k]; if(x[l]-x[l-1]<=x[r+1]-x[l] && l>1){ ans+=x[l]-x[l-1];l--; } else if(r<n){ ans+=x[r]-x[l]; s=0; } } else{ ans+=x[nx[r][k]]-x[r]; r=nx[r][k]; if(x[r+1]-x[r]<=x[r]-x[l-1] && r<n){ ans+=x[r+1]-x[r];r++; } else if(l>1){ ans+=x[r]-x[l]; s=1; } } } cout<<ans<<endl; } } main(){ B=clock(); ios; int T=1; //cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<<i<<": "; solve(); } E=clock(); cerr<<"\n\n\n\nTIME: "<<((float)E-B)/CLOCKS_PER_SEC<<" SECONDS"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 565 ms | 540436 KB | Output is correct |
2 | Correct | 525 ms | 540552 KB | Output is correct |
3 | Correct | 522 ms | 540520 KB | Output is correct |
4 | Correct | 515 ms | 540500 KB | Output is correct |
5 | Correct | 520 ms | 540628 KB | Output is correct |
6 | Correct | 536 ms | 540756 KB | Output is correct |
7 | Correct | 512 ms | 540548 KB | Output is correct |
8 | Correct | 518 ms | 540532 KB | Output is correct |
9 | Correct | 520 ms | 540764 KB | Output is correct |
10 | Correct | 514 ms | 540544 KB | Output is correct |
11 | Correct | 517 ms | 540752 KB | Output is correct |
12 | Correct | 521 ms | 540656 KB | Output is correct |
13 | Correct | 523 ms | 540440 KB | Output is correct |
14 | Correct | 524 ms | 540500 KB | Output is correct |
15 | Correct | 531 ms | 540588 KB | Output is correct |
16 | Correct | 515 ms | 540388 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 565 ms | 540436 KB | Output is correct |
2 | Correct | 525 ms | 540552 KB | Output is correct |
3 | Correct | 522 ms | 540520 KB | Output is correct |
4 | Correct | 515 ms | 540500 KB | Output is correct |
5 | Correct | 520 ms | 540628 KB | Output is correct |
6 | Correct | 536 ms | 540756 KB | Output is correct |
7 | Correct | 512 ms | 540548 KB | Output is correct |
8 | Correct | 518 ms | 540532 KB | Output is correct |
9 | Correct | 520 ms | 540764 KB | Output is correct |
10 | Correct | 514 ms | 540544 KB | Output is correct |
11 | Correct | 517 ms | 540752 KB | Output is correct |
12 | Correct | 521 ms | 540656 KB | Output is correct |
13 | Correct | 523 ms | 540440 KB | Output is correct |
14 | Correct | 524 ms | 540500 KB | Output is correct |
15 | Correct | 531 ms | 540588 KB | Output is correct |
16 | Correct | 515 ms | 540388 KB | Output is correct |
17 | Correct | 566 ms | 544072 KB | Output is correct |
18 | Correct | 572 ms | 543960 KB | Output is correct |
19 | Correct | 565 ms | 544036 KB | Output is correct |
20 | Correct | 558 ms | 543912 KB | Output is correct |
21 | Correct | 557 ms | 544072 KB | Output is correct |
22 | Correct | 579 ms | 544096 KB | Output is correct |
23 | Correct | 565 ms | 544084 KB | Output is correct |
24 | Correct | 571 ms | 543824 KB | Output is correct |
25 | Correct | 569 ms | 543884 KB | Output is correct |
26 | Correct | 576 ms | 544084 KB | Output is correct |
27 | Correct | 569 ms | 543896 KB | Output is correct |
28 | Correct | 563 ms | 543828 KB | Output is correct |
29 | Correct | 566 ms | 543988 KB | Output is correct |
30 | Correct | 565 ms | 543916 KB | Output is correct |
31 | Correct | 566 ms | 543824 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 530 ms | 540464 KB | Output is correct |
2 | Correct | 522 ms | 540608 KB | Output is correct |
3 | Correct | 515 ms | 540752 KB | Output is correct |
4 | Correct | 529 ms | 540480 KB | Output is correct |
5 | Correct | 528 ms | 540604 KB | Output is correct |
6 | Correct | 526 ms | 540496 KB | Output is correct |
7 | Correct | 714 ms | 545888 KB | Output is correct |
8 | Correct | 714 ms | 546052 KB | Output is correct |
9 | Correct | 710 ms | 546204 KB | Output is correct |
10 | Correct | 698 ms | 546296 KB | Output is correct |
11 | Correct | 711 ms | 545956 KB | Output is correct |
12 | Correct | 708 ms | 546084 KB | Output is correct |
13 | Correct | 552 ms | 544340 KB | Output is correct |
14 | Correct | 539 ms | 541780 KB | Output is correct |
15 | Incorrect | 682 ms | 547136 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 565 ms | 540436 KB | Output is correct |
2 | Correct | 525 ms | 540552 KB | Output is correct |
3 | Correct | 522 ms | 540520 KB | Output is correct |
4 | Correct | 515 ms | 540500 KB | Output is correct |
5 | Correct | 520 ms | 540628 KB | Output is correct |
6 | Correct | 536 ms | 540756 KB | Output is correct |
7 | Correct | 512 ms | 540548 KB | Output is correct |
8 | Correct | 518 ms | 540532 KB | Output is correct |
9 | Correct | 520 ms | 540764 KB | Output is correct |
10 | Correct | 514 ms | 540544 KB | Output is correct |
11 | Correct | 517 ms | 540752 KB | Output is correct |
12 | Correct | 521 ms | 540656 KB | Output is correct |
13 | Correct | 523 ms | 540440 KB | Output is correct |
14 | Correct | 524 ms | 540500 KB | Output is correct |
15 | Correct | 531 ms | 540588 KB | Output is correct |
16 | Correct | 515 ms | 540388 KB | Output is correct |
17 | Correct | 566 ms | 544072 KB | Output is correct |
18 | Correct | 572 ms | 543960 KB | Output is correct |
19 | Correct | 565 ms | 544036 KB | Output is correct |
20 | Correct | 558 ms | 543912 KB | Output is correct |
21 | Correct | 557 ms | 544072 KB | Output is correct |
22 | Correct | 579 ms | 544096 KB | Output is correct |
23 | Correct | 565 ms | 544084 KB | Output is correct |
24 | Correct | 571 ms | 543824 KB | Output is correct |
25 | Correct | 569 ms | 543884 KB | Output is correct |
26 | Correct | 576 ms | 544084 KB | Output is correct |
27 | Correct | 569 ms | 543896 KB | Output is correct |
28 | Correct | 563 ms | 543828 KB | Output is correct |
29 | Correct | 566 ms | 543988 KB | Output is correct |
30 | Correct | 565 ms | 543916 KB | Output is correct |
31 | Correct | 566 ms | 543824 KB | Output is correct |
32 | Correct | 530 ms | 540464 KB | Output is correct |
33 | Correct | 522 ms | 540608 KB | Output is correct |
34 | Correct | 515 ms | 540752 KB | Output is correct |
35 | Correct | 529 ms | 540480 KB | Output is correct |
36 | Correct | 528 ms | 540604 KB | Output is correct |
37 | Correct | 526 ms | 540496 KB | Output is correct |
38 | Correct | 714 ms | 545888 KB | Output is correct |
39 | Correct | 714 ms | 546052 KB | Output is correct |
40 | Correct | 710 ms | 546204 KB | Output is correct |
41 | Correct | 698 ms | 546296 KB | Output is correct |
42 | Correct | 711 ms | 545956 KB | Output is correct |
43 | Correct | 708 ms | 546084 KB | Output is correct |
44 | Correct | 552 ms | 544340 KB | Output is correct |
45 | Correct | 539 ms | 541780 KB | Output is correct |
46 | Incorrect | 682 ms | 547136 KB | Output isn't correct |
47 | Halted | 0 ms | 0 KB | - |