Submission #1047373

#TimeUsernameProblemLanguageResultExecution timeMemory
1047373VMaksimoski008Circle Passing (EGOI24_circlepassing)C++17
100 / 100
164 ms2396 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; vector<int> v(m), v2; for(int &x : v) cin >> x; sort(v.begin(), v.end()); auto D = [&](int x, int y) { return min(max(x, y) - min(x, y), 2 * n - max(x, y) + min(x, y)); }; while(q--) { int x, y; cin >> x >> y; int ans = D(x, y); ans = min(ans, D(x, v[0]) + D(v[0]+n, y) + 1); ans = min(ans, D(x, v.back()+n) + D(v.back(), y) + 1); int p = lower_bound(v.begin(), v.end(), x) - v.begin(); if(p != m) ans = min(ans, D(x, v[p]) + D(v[p]+n, y) + 1); if(p > 0) ans = min(ans, D(x, v[p-1]) + D(v[p-1]+n, y) + 1); p = lower_bound(v.begin(), v.end(), x-n) - v.begin(); if(p != m) ans = min(ans, D(x, v[p]+n) + D(v[p], y) + 1); if(p > 0) ans = min(ans, D(x, v[p-1]+n) + D(v[p-1], y) + 1); cout << ans << '\n'; } return 0; }
#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...