Submission #1168392

#TimeUsernameProblemLanguageResultExecution timeMemory
1168392pyrrosCircle Passing (EGOI24_circlepassing)C++20
0 / 100
20 ms456 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main()
{
	int n, me, q;
	cin>>n>>me>>q;
	vector<int> bff;
	int pivot = 0;
	map<int, bool> m;
	vector<int> store;
	for(int i = 0; i < me; i++)
	{
		int a; cin>>a;
		bff.push_back(a);
		m[a] = 1;
		m[a+n] = 1;
		store.push_back(a);
		store.push_back(a+n);
	}
	//st1
	//int diff = pivot;
	int new_target = 0;
	while(q--)
	{
		int x, y; cin>>x>>y;
		pivot = x;
		if(y > x){
		new_target = y-pivot;
	}else if(y < x)
	{
		new_target = 2*n-(x-y);
	}
	//cout<<"new_target: "<<new_target<<endl;
	int answer = 1e9;
	
	
	//last segment to decide and compare if it is better to not use any bridge
	if(new_target < n)
	{
			answer = min(answer, new_target);
	}
	else if(new_target > n)
	{
		answer = min(answer, 2*n-new_target);
	}else if(new_target == n)
	{
		answer = min(answer, n);
	}
	for(int i = 0; i < 2*me; i++)
	{
		int hole = store[i];
		int hole_new = hole-x;
		if(hole_new<0) hole_new = 2*n+hole_new;
		//cout<<"hole: "<<hole<<" "<<"new_hole: "<<hole_new<<endl;
		//left side
		if(hole_new > n)
		{
			int temp = 2*n-hole_new + 1 + abs((hole_new-n)-new_target);
			//cout<<"temp: "<<temp<<endl;
			answer = min(answer, temp);
		}
		//right side
		else if(hole_new<n)
		{
			int temp = hole_new + 1 + abs((hole_new+n)-new_target);
			//cout<<"temp: "<<temp<<endl;
			answer = min(answer, temp);
		}else if(hole_new == n)
		{
			int h = 1;
			if(m[(n+x)%2*n] == 1) answer = min(answer, h);
			else answer = min(answer, n);
		}
		
	}
	cout<<answer<<'\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...