답안 #773185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773185 2023-07-04T16:13:52 Z xetrk 원 고르기 (APIO18_circle_selection) C++14
7 / 100
3000 ms 68696 KB
#pragma warning(disable:4996)

#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef long double ld;

int n;

vector<vector<ll>> circle;

vector<pair<ll, int>> sortRadius;// , sortY;

set<pair<ll, int>> sortX, sortY;

int ans[301000];

inline ll GetDist(ll x1, ll y1, ll x2, ll y2)
{
	// 아 좌표값 마이너스도 들어오네
	ll xx = max(x1, x2) - min(x1, x2);
	ll yy = max(y1, y2) - min(y1, y2);
	return (xx * xx) + (yy * yy);
}



bool comp(const pair<ll,int>& a, const pair<ll,int>& b)
{
	if (a.first == b.first)
		return a.second < b.second;
	return a.first < b.first;
}

bool compSort(const pair<ll, int>& a, const pair<ll, int>& b)
{
	if (a.first == b.first)
		return a.second < b.second;
	
	return a.first > b.first;
}

int main()
{
	ll x, y, r, r2;
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%lld %lld %lld", &x, &y, &r);
		//x = 1, y = 1, r = 3;
		circle.push_back({ x,y,r });
		sortRadius.push_back({ r,i });
		sortX.insert({ x,i });
		sortY.insert({ y,i });
	}

	sort(sortRadius.begin(), sortRadius.end(), compSort);
	//sort(sortX.begin(), sortX.end());
	//sort(sortY.begin(), sortY.end());


	int cur, curcmp;
	//int xMin, xMax, yMin, yMax;
	ll rr;

	fill(ans, ans + n + 2, -1);

	for (int curDelete = 0; curDelete < n; curDelete++)
	{
		cur = sortRadius[curDelete].second;
		if (ans[cur] != -1)
			continue;


		x = circle[cur][0], y = circle[cur][1], r = circle[cur][2];
		if (curDelete < n - 1)
			r2 = r + sortRadius[curDelete + 1].first + 1;
		else
			r2 = r * 2 + 1;
		
		// a이하를 찾아야하는데 lower bound는  a이상인걸 찾으니까.. 근데 그 이하인걸 찾아야하니 1빼줌
		auto xMin2 = lower_bound(sortX.begin(), sortX.end(), pair<ll, int>(x - r2, -1), comp);
		auto xMax2 = upper_bound(sortX.begin(), sortX.end(), pair<ll, int>(x + r2, 301000), comp);

		auto yMin2 = lower_bound(sortY.begin(), sortY.end(), pair<ll, int>(y - r2, -1), comp);
		auto yMax2 = upper_bound(sortY.begin(), sortY.end(), pair<ll, int>(y + r2, 301000), comp);


		if (xMin2 != sortX.begin()) xMin2--;
		if (yMin2 != sortY.begin()) yMin2--;


		//xMin--;
		//yMin--;

		//if (xMin < 0) xMin = 0;
		//if (yMin < 0) yMin = 0;

		//if (xMin >= sortX.size()) xMin = sortX.size() - 1;
		//if (yMin >= sortY.size()) yMin = sortY.size() - 1;
		//if (xMax >= sortX.size()) xMax = sortX.size() - 1;
		//if (yMax >= sortY.size()) yMax = sortY.size() - 1;

		//xMin = 0, yMin = 0, xMax = n - 1, yMax = n - 1;


		ans[cur] = cur;

		if (std::distance(xMin2, xMax2) < std::distance(yMin2, yMax2))
		{

			vector<set<pair<ll, int>>::iterator> eraseItems;

			for (set<pair<ll, int>>::iterator xx = xMin2; xx != xMax2; xx++)
			{
				curcmp = (*xx).second;
				rr = r + circle[curcmp][2];
				if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= rr * rr)
				{
					ans[curcmp] = cur;
					//sortX.erase(sortX.begin() + i);
					//sortX.erase((*xx));
					eraseItems.push_back(xx);
				}
			}

			for (auto e : eraseItems)
			{
				sortX.erase((*e));
			}
		}
		else
		{
			vector<set<pair<ll, int>>::iterator> eraseItems;

			for (set<pair<ll, int>>::iterator yy = yMin2; yy != yMax2; yy++)
			{
				curcmp = (*yy).second;
				rr = r + circle[curcmp][2];
				if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= rr * rr)
				{
					ans[curcmp] = cur;
					//sortX.erase(sortX.begin() + i);
					//sortX.erase((*xx));
					eraseItems.push_back(yy);
				}
			}

			for (auto e : eraseItems)
			{
				sortY.erase((*e));
			}
		}


		/*
		if (xMax - xMin < yMax - yMin)
		{
			for (int i = xMax; i >= xMin; i--)
			{
				curcmp = sortX[i].second;
				if (ans[curcmp] != -1) continue;
				rr = r + circle[curcmp][2];
				if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= rr * rr)
				{
					ans[curcmp] = cur;
					//sortX.erase(sortX.begin() + i);
				}
			}
		}
		else
		{

			for (int i = yMax; i >= yMin; i--)
			{
				curcmp = sortY[i].second;
				if (ans[curcmp]!= -1) continue;
				rr = r + circle[curcmp][2];
				if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= rr * rr)
				{
					ans[curcmp] = cur;
					//sortY.erase(sortY.begin() + i);
				}
			}
		}*/
	}

	for (int i = 0; i < n; i++)
		printf("%d ", ans[i]+1);

	return 0;
}

Compilation message

circle_selection.cpp:1: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    1 | #pragma warning(disable:4996)
      | 
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
circle_selection.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%lld %lld %lld", &x, &y, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 6 ms 1364 KB Output is correct
20 Correct 6 ms 1364 KB Output is correct
21 Correct 7 ms 1364 KB Output is correct
22 Correct 1761 ms 1332 KB Output is correct
23 Correct 1745 ms 1324 KB Output is correct
24 Correct 1745 ms 1328 KB Output is correct
25 Correct 1747 ms 1324 KB Output is correct
26 Correct 1709 ms 1324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 905 ms 68668 KB Output is correct
2 Correct 980 ms 65416 KB Output is correct
3 Correct 981 ms 66024 KB Output is correct
4 Correct 910 ms 68696 KB Output is correct
5 Execution timed out 3070 ms 60120 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 3076 ms 20328 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3079 ms 60192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 6 ms 1364 KB Output is correct
20 Correct 6 ms 1364 KB Output is correct
21 Correct 7 ms 1364 KB Output is correct
22 Correct 1761 ms 1332 KB Output is correct
23 Correct 1745 ms 1324 KB Output is correct
24 Correct 1745 ms 1328 KB Output is correct
25 Correct 1747 ms 1324 KB Output is correct
26 Correct 1709 ms 1324 KB Output is correct
27 Correct 17 ms 2572 KB Output is correct
28 Correct 12 ms 2572 KB Output is correct
29 Correct 12 ms 2480 KB Output is correct
30 Execution timed out 3098 ms 2316 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 6 ms 1364 KB Output is correct
20 Correct 6 ms 1364 KB Output is correct
21 Correct 7 ms 1364 KB Output is correct
22 Correct 1761 ms 1332 KB Output is correct
23 Correct 1745 ms 1324 KB Output is correct
24 Correct 1745 ms 1328 KB Output is correct
25 Correct 1747 ms 1324 KB Output is correct
26 Correct 1709 ms 1324 KB Output is correct
27 Correct 905 ms 68668 KB Output is correct
28 Correct 980 ms 65416 KB Output is correct
29 Correct 981 ms 66024 KB Output is correct
30 Correct 910 ms 68696 KB Output is correct
31 Execution timed out 3070 ms 60120 KB Time limit exceeded
32 Halted 0 ms 0 KB -