Submission #1052990

#TimeUsernameProblemLanguageResultExecution timeMemory
1052990LudisseyCircle Passing (EGOI24_circlepassing)C++17
100 / 100
65 ms13368 KiB
#include <bits/stdc++.h> #define int long long #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() using namespace std; int N,M,Q; int calc(int x, int y){ return min(abs(y-x), min(((N*2)-x)+y, ((N*2)-y)+x)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M >> Q; vector<int> k(2*M); for (int i = 0; i < M; i++) { int x; cin >> x; k[i*2]=x; k[i*2+1]=x+N; } sort(all(k)); for (int i = 0; i < Q; i++) { int x,y; cin >> x >> y; int lb=upper_bound(all(k), x)-k.begin(); int mn=calc(x,y); if(lb<sz(k)) mn=min(mn,calc(x, k[lb])+calc((k[lb]+N)%(N*2),y)+1); else if(sz(k)>0) mn=min(mn,calc(x, k[0])+calc((k[0]+N)%(N*2),y)+1); if(lb>0) mn=min(mn,calc(x, k[lb-1])+calc((k[lb-1]+N)%(N*2),y)+1); else if(sz(k)>0) mn=min(mn,calc(x, k[sz(k)-1])+calc((k[sz(k)-1]+N)%(N*2),y)+1); cout << mn << "\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...