Submission #1120770

#TimeUsernameProblemLanguageResultExecution timeMemory
1120770ezzzayCircle Passing (EGOI24_circlepassing)C++14
14 / 100
181 ms11264 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); if(a<n)v.pb(a+n); else v.pb(a-n); } sort(v.begin(),v.end()); while(q--){ int a,b; cin>>a>>b; auto it=upper_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...