제출 #1151462

#제출 시각아이디문제언어결과실행 시간메모리
1151462Ghulam_JunaidCircle Passing (EGOI24_circlepassing)C++20
100 / 100
312 ms47596 KiB
#include <bits/stdc++.h> using namespace std; int n, m, q; set<int> st; int get(int x, int y){ if (x >= y) swap(x, y); return min(y - x, 2 * n - (y - x)); } int real_get(int x, int y){ int res = get(x, y); if (st.find(x) != st.end()) x += ((x >= n) ? -n : n); res = min(res, 1 + get(x, y)); return res; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> q; for (int i = 0; i < m; i ++){ int x; cin >> x; st.insert(x); st.insert(x + ((x >= n) ? -n : n)); } for (int i = 0; i < q; i ++){ int x, y; cin >> x >> y; int ans = real_get(x, y); auto it = st.lower_bound(x); if (it != st.end()) ans = min(ans, real_get(x, *it) + real_get(*it, y)); if (it != st.begin()){ it--; ans = min(ans, real_get(x, *it) + real_get(*it, y)); } ans = min(ans, real_get(x, *st.begin()) + real_get(*st.begin(), y)); ans = min(ans, real_get(x, *st.rbegin()) + real_get(*st.rbegin(), 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...