제출 #1345089

#제출 시각아이디문제언어결과실행 시간메모리
1345089muhammad-ahmadCircle Passing (EGOI24_circlepassing)C++20
0 / 100
532 ms1114112 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int n, m, q; 

int dist(int x, int y){
	int ans;
	if (x < y) ans = min(y - x, x + 2 * n - y);
	else ans = min(x - y, y + 2 * n - x);
	return ans;
}

signed main(){
	cin >> n >> m >> q;
	bool f[2 * n] = {};
	for (int i = 1; i <= m; i++){
		int k; cin >> k;
		f[k] = f[k + n] = 1;
	}	
	int lst = -1;
	int l[2 * n], r[2 * n];
	for (int i = 0; i < 6 * n; i++){
		if (f[i % (2 * n)]) lst = i % (2 * n);
		r[i] = lst;
	}
	lst = -1;
	for (int i = 6 * n - 1; i >= 0; i--){
		if (f[i % (2 * n)]) lst = i % (2 * n);
		l[i] = lst;
	}
	
	for (int Q = 1; Q <= q; Q++){
		int x, y; cin >> x >> y;
		int ans = dist(x, y);
		ans = min(ans, dist(l[x], x) + dist((l[x] + n) % n, y));
		ans = min(ans, dist(r[x], x) + dist((r[x] + n) % n, y));
		cout << ans << endl;
	}
}
#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...