답안 #773077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773077 2023-07-04T14:47:10 Z xetrk 원 고르기 (APIO18_circle_selection) C++14
87 / 100
3000 ms 37840 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, 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.push_back({ x,i });
		sortY.push_back({ 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;

	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];
		r2 = r * 3 + 2;
		
		// a이하를 찾아야하는데 lower bound는  a이상인걸 찾으니까.. 근데 그 이하인걸 찾아야하니 1빼줌
		xMin = lower_bound(sortX.begin(), sortX.end(), pair<ll, int>(x - r2, -1), comp) - sortX.begin();
		xMax = upper_bound(sortX.begin(), sortX.end(), pair<ll, int>(x + r2, 301000), comp) - sortX.begin();

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

		xMin--;
		yMin--;

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

		if (xMin >= n) xMin = n - 1;
		if (yMin >= n) yMin = n - 1;
		if (xMax >= n) xMax = n - 1;
		if (yMax >= n) yMax = n - 1;

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


		ans[cur] = cur;

		if (xMax - xMin < yMax - yMin)
		{
			curcmp = sortX[max(0, xMin - 1)].second;
			int beforeX = circle[curcmp][0];

			/*
			for (int i = xMin; i >= 0; i--)
			{
				curcmp = sortX[i].second;
				if (beforeX > circle[curcmp][0])
					break;
				if (ans[curcmp] != -1) continue;
				if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= (ll)(((r + circle[curcmp][2]) * (r + circle[curcmp][2]))))
					ans[curcmp] = cur;

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


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

			//}


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

	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:104:8: warning: unused variable 'beforeX' [-Wunused-variable]
  104 |    int beforeX = circle[curcmp][0];
      |        ^~~~~~~
circle_selection.cpp:128:8: warning: unused variable 'beforeY' [-Wunused-variable]
  128 |    int beforeY = circle[curcmp][1];
      |        ^~~~~~~
circle_selection.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
circle_selection.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%lld %lld %lld", &x, &y, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 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 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 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 304 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 1236 KB Output is correct
20 Correct 4 ms 1200 KB Output is correct
21 Correct 5 ms 1236 KB Output is correct
22 Correct 6 ms 1108 KB Output is correct
23 Correct 5 ms 1108 KB Output is correct
24 Correct 6 ms 1236 KB Output is correct
25 Correct 5 ms 1216 KB Output is correct
26 Correct 6 ms 1140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 34548 KB Output is correct
2 Correct 214 ms 34556 KB Output is correct
3 Correct 201 ms 34264 KB Output is correct
4 Correct 201 ms 34532 KB Output is correct
5 Correct 217 ms 34288 KB Output is correct
6 Correct 275 ms 34540 KB Output is correct
7 Correct 220 ms 34412 KB Output is correct
8 Correct 231 ms 34420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 207 ms 11908 KB Output is correct
3 Correct 1119 ms 34464 KB Output is correct
4 Correct 1069 ms 34504 KB Output is correct
5 Correct 1509 ms 33608 KB Output is correct
6 Correct 380 ms 18260 KB Output is correct
7 Correct 118 ms 9928 KB Output is correct
8 Correct 18 ms 2408 KB Output is correct
9 Correct 1177 ms 37620 KB Output is correct
10 Correct 2013 ms 37764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 624 ms 34484 KB Output is correct
2 Correct 460 ms 34532 KB Output is correct
3 Correct 1162 ms 34072 KB Output is correct
4 Correct 469 ms 37520 KB Output is correct
5 Correct 467 ms 37556 KB Output is correct
6 Correct 534 ms 37072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 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 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 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 304 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 1236 KB Output is correct
20 Correct 4 ms 1200 KB Output is correct
21 Correct 5 ms 1236 KB Output is correct
22 Correct 6 ms 1108 KB Output is correct
23 Correct 5 ms 1108 KB Output is correct
24 Correct 6 ms 1236 KB Output is correct
25 Correct 5 ms 1216 KB Output is correct
26 Correct 6 ms 1140 KB Output is correct
27 Correct 7 ms 1800 KB Output is correct
28 Correct 7 ms 1848 KB Output is correct
29 Correct 7 ms 1800 KB Output is correct
30 Correct 11 ms 1792 KB Output is correct
31 Correct 14 ms 1912 KB Output is correct
32 Correct 12 ms 1800 KB Output is correct
33 Correct 69 ms 14540 KB Output is correct
34 Correct 70 ms 14472 KB Output is correct
35 Correct 72 ms 14340 KB Output is correct
36 Correct 142 ms 13944 KB Output is correct
37 Correct 161 ms 14048 KB Output is correct
38 Correct 155 ms 14136 KB Output is correct
39 Correct 608 ms 12484 KB Output is correct
40 Correct 624 ms 12476 KB Output is correct
41 Correct 670 ms 12564 KB Output is correct
42 Correct 322 ms 13028 KB Output is correct
43 Correct 114 ms 14044 KB Output is correct
44 Correct 111 ms 14008 KB Output is correct
45 Correct 117 ms 13992 KB Output is correct
46 Correct 117 ms 13992 KB Output is correct
47 Correct 131 ms 14004 KB Output is correct
48 Correct 111 ms 14000 KB Output is correct
49 Correct 115 ms 14008 KB Output is correct
50 Correct 113 ms 14000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 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 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 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 304 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 1236 KB Output is correct
20 Correct 4 ms 1200 KB Output is correct
21 Correct 5 ms 1236 KB Output is correct
22 Correct 6 ms 1108 KB Output is correct
23 Correct 5 ms 1108 KB Output is correct
24 Correct 6 ms 1236 KB Output is correct
25 Correct 5 ms 1216 KB Output is correct
26 Correct 6 ms 1140 KB Output is correct
27 Correct 210 ms 34548 KB Output is correct
28 Correct 214 ms 34556 KB Output is correct
29 Correct 201 ms 34264 KB Output is correct
30 Correct 201 ms 34532 KB Output is correct
31 Correct 217 ms 34288 KB Output is correct
32 Correct 275 ms 34540 KB Output is correct
33 Correct 220 ms 34412 KB Output is correct
34 Correct 231 ms 34420 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 207 ms 11908 KB Output is correct
37 Correct 1119 ms 34464 KB Output is correct
38 Correct 1069 ms 34504 KB Output is correct
39 Correct 1509 ms 33608 KB Output is correct
40 Correct 380 ms 18260 KB Output is correct
41 Correct 118 ms 9928 KB Output is correct
42 Correct 18 ms 2408 KB Output is correct
43 Correct 1177 ms 37620 KB Output is correct
44 Correct 2013 ms 37764 KB Output is correct
45 Correct 624 ms 34484 KB Output is correct
46 Correct 460 ms 34532 KB Output is correct
47 Correct 1162 ms 34072 KB Output is correct
48 Correct 469 ms 37520 KB Output is correct
49 Correct 467 ms 37556 KB Output is correct
50 Correct 534 ms 37072 KB Output is correct
51 Correct 7 ms 1800 KB Output is correct
52 Correct 7 ms 1848 KB Output is correct
53 Correct 7 ms 1800 KB Output is correct
54 Correct 11 ms 1792 KB Output is correct
55 Correct 14 ms 1912 KB Output is correct
56 Correct 12 ms 1800 KB Output is correct
57 Correct 69 ms 14540 KB Output is correct
58 Correct 70 ms 14472 KB Output is correct
59 Correct 72 ms 14340 KB Output is correct
60 Correct 142 ms 13944 KB Output is correct
61 Correct 161 ms 14048 KB Output is correct
62 Correct 155 ms 14136 KB Output is correct
63 Correct 608 ms 12484 KB Output is correct
64 Correct 624 ms 12476 KB Output is correct
65 Correct 670 ms 12564 KB Output is correct
66 Correct 322 ms 13028 KB Output is correct
67 Correct 114 ms 14044 KB Output is correct
68 Correct 111 ms 14008 KB Output is correct
69 Correct 117 ms 13992 KB Output is correct
70 Correct 117 ms 13992 KB Output is correct
71 Correct 131 ms 14004 KB Output is correct
72 Correct 111 ms 14000 KB Output is correct
73 Correct 115 ms 14008 KB Output is correct
74 Correct 113 ms 14000 KB Output is correct
75 Correct 264 ms 37652 KB Output is correct
76 Correct 248 ms 37816 KB Output is correct
77 Correct 254 ms 37840 KB Output is correct
78 Correct 263 ms 37584 KB Output is correct
79 Correct 339 ms 37680 KB Output is correct
80 Correct 240 ms 37556 KB Output is correct
81 Correct 935 ms 37596 KB Output is correct
82 Correct 844 ms 37584 KB Output is correct
83 Correct 813 ms 37584 KB Output is correct
84 Correct 1492 ms 37660 KB Output is correct
85 Correct 858 ms 37580 KB Output is correct
86 Correct 764 ms 37632 KB Output is correct
87 Correct 999 ms 37632 KB Output is correct
88 Execution timed out 3050 ms 36268 KB Time limit exceeded
89 Halted 0 ms 0 KB -