제출 #1167476

#제출 시각아이디문제언어결과실행 시간메모리
1167476emptypringlescanCircle Passing (EGOI24_circlepassing)C++20
100 / 100
71 ms8624 KiB
#include <bits/stdc++.h> using namespace std; int n,m,q; long long dist(long long x, long long y){ long long yey=abs(x-y); return min(yey,2ll*n-yey); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> q; vector<long long> arr; for(int i=0; i<m; i++){ long long x; cin >> x; arr.push_back(x); arr.push_back(x+n); } sort(arr.begin(),arr.end()); for(int i=0; i<q; i++){ int x,y; cin >> x >> y; long long ans=dist(x,y); int ind=lower_bound(arr.begin(),arr.end(),x)-arr.begin(); int tp; if(ind==0) tp=arr[(int)arr.size()-1]; else tp=arr[ind-1]; ans=min(ans,dist(x,tp)+1+dist((tp+n)%(2*n),y)); if(ind==(int)arr.size()) tp=arr[0]; else tp=arr[ind]; ans=min(ans,dist(x,tp)+1+dist((tp+n)%(2*n),y)); cout << ans << '\n'; } }
#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...