제출 #1120779

#제출 시각아이디문제언어결과실행 시간메모리
1120779ezzzayCircle Passing (EGOI24_circlepassing)C++14
14 / 100
198 ms10656 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back const int N=3e5+5; vector<int>ans; int n,m,q; int fun(int x, int y){ int h=abs(y-x); return min(h,2*n-h); } signed main(){ cin>>n>>m>>q; vector<int>v={-1,INT_MAX}; for(int i=1;i<=m;i++){ int a; cin>>a; v.pb(a); v.pb(a+n); } sort(v.begin(),v.end()); while(q--){ int a,b; cin>>a>>b; auto it=lower_bound(v.begin(),v.end(),a); int x=*it; it--; int y= *it; int p=fun(a,b); if(x!=INT_MAX){ int z; if(x<n)z=n+x; else z=x-n; p=min(p,fun(a,x)+fun(b,z)+1); } if(y!=-1){ int z; if(y<n)z=n+y; else z=y-n; p=min(p,fun(a,y)+fun(b,z)+1); } ans.pb(p); } for(auto a:ans)cout<<a<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...