제출 #1232404

#제출 시각아이디문제언어결과실행 시간메모리
1232404yixuan19Circle Passing (EGOI24_circlepassing)C++20
14 / 100
131 ms4532 KiB
//#include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; int N, M, Q, f, start, target, min_time, r, l; int find_friend(int f){ if (f >= N) return f-N; return f + N; } int dist(int a, int b){ if (b > a){ swap(a,b); } return min(a-b,2*N - a + b); } int main(){ cin >> N >> M >> Q; vector<int> friends; for (int i = 0; i < M; ++i){ cin >> f; friends.push_back(f); friends.push_back(f+N); } sort(friends.begin(), friends.end()); for (int i = 0; i < Q; ++i){ cin >> start >> target; min_time = dist(start,target); if (start >= friends[friends.size()-1]){ r = 0; l = friends.size()-1; }else if (start <= friends[0]){ r = 0; l = friends.size()-1; } r = lower_bound(friends.begin(), friends.end(),start) - friends.begin(); l = r-1; //cout<<friends[l]<<' '<<friends[r]<<endl; min_time = min(min_time, dist(start,friends[r]) + dist(find_friend(friends[r]),target) + 1); min_time = min(min_time, dist(start,friends[l]) + dist(find_friend(friends[l]),target) + 1); cout<<min_time<<'\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...