답안 #773072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773072 2023-07-04T14:45:26 Z xetrk 원 고르기 (APIO18_circle_selection) C++14
87 / 100
3000 ms 43112 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: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 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 260 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 308 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 312 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 456 KB Output is correct
19 Correct 4 ms 1156 KB Output is correct
20 Correct 4 ms 1236 KB Output is correct
21 Correct 4 ms 1212 KB Output is correct
22 Correct 7 ms 1136 KB Output is correct
23 Correct 6 ms 1120 KB Output is correct
24 Correct 6 ms 1108 KB Output is correct
25 Correct 7 ms 1108 KB Output is correct
26 Correct 6 ms 1212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 34068 KB Output is correct
2 Correct 206 ms 34060 KB Output is correct
3 Correct 194 ms 33796 KB Output is correct
4 Correct 194 ms 34036 KB Output is correct
5 Correct 210 ms 33884 KB Output is correct
6 Correct 322 ms 35088 KB Output is correct
7 Correct 226 ms 35068 KB Output is correct
8 Correct 236 ms 35144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 210 ms 11396 KB Output is correct
3 Correct 1141 ms 35104 KB Output is correct
4 Correct 1016 ms 35204 KB Output is correct
5 Correct 1395 ms 34252 KB Output is correct
6 Correct 355 ms 18904 KB Output is correct
7 Correct 105 ms 10620 KB Output is correct
8 Correct 16 ms 2928 KB Output is correct
9 Correct 1123 ms 42036 KB Output is correct
10 Correct 1917 ms 42384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 683 ms 33956 KB Output is correct
2 Correct 584 ms 35184 KB Output is correct
3 Correct 1235 ms 34736 KB Output is correct
4 Correct 500 ms 41372 KB Output is correct
5 Correct 498 ms 41604 KB Output is correct
6 Correct 505 ms 41788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 260 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 308 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 312 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 456 KB Output is correct
19 Correct 4 ms 1156 KB Output is correct
20 Correct 4 ms 1236 KB Output is correct
21 Correct 4 ms 1212 KB Output is correct
22 Correct 7 ms 1136 KB Output is correct
23 Correct 6 ms 1120 KB Output is correct
24 Correct 6 ms 1108 KB Output is correct
25 Correct 7 ms 1108 KB Output is correct
26 Correct 6 ms 1212 KB Output is correct
27 Correct 8 ms 1804 KB Output is correct
28 Correct 8 ms 1864 KB Output is correct
29 Correct 9 ms 1812 KB Output is correct
30 Correct 12 ms 1808 KB Output is correct
31 Correct 12 ms 1800 KB Output is correct
32 Correct 11 ms 1804 KB Output is correct
33 Correct 69 ms 14580 KB Output is correct
34 Correct 70 ms 14504 KB Output is correct
35 Correct 74 ms 14328 KB Output is correct
36 Correct 145 ms 13920 KB Output is correct
37 Correct 140 ms 14088 KB Output is correct
38 Correct 153 ms 14132 KB Output is correct
39 Correct 667 ms 12484 KB Output is correct
40 Correct 639 ms 12480 KB Output is correct
41 Correct 666 ms 12456 KB Output is correct
42 Correct 342 ms 13048 KB Output is correct
43 Correct 115 ms 13992 KB Output is correct
44 Correct 143 ms 14024 KB Output is correct
45 Correct 122 ms 14040 KB Output is correct
46 Correct 114 ms 14000 KB Output is correct
47 Correct 113 ms 14044 KB Output is correct
48 Correct 113 ms 13968 KB Output is correct
49 Correct 118 ms 14096 KB Output is correct
50 Correct 111 ms 13996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 260 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 308 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 312 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 456 KB Output is correct
19 Correct 4 ms 1156 KB Output is correct
20 Correct 4 ms 1236 KB Output is correct
21 Correct 4 ms 1212 KB Output is correct
22 Correct 7 ms 1136 KB Output is correct
23 Correct 6 ms 1120 KB Output is correct
24 Correct 6 ms 1108 KB Output is correct
25 Correct 7 ms 1108 KB Output is correct
26 Correct 6 ms 1212 KB Output is correct
27 Correct 206 ms 34068 KB Output is correct
28 Correct 206 ms 34060 KB Output is correct
29 Correct 194 ms 33796 KB Output is correct
30 Correct 194 ms 34036 KB Output is correct
31 Correct 210 ms 33884 KB Output is correct
32 Correct 322 ms 35088 KB Output is correct
33 Correct 226 ms 35068 KB Output is correct
34 Correct 236 ms 35144 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 210 ms 11396 KB Output is correct
37 Correct 1141 ms 35104 KB Output is correct
38 Correct 1016 ms 35204 KB Output is correct
39 Correct 1395 ms 34252 KB Output is correct
40 Correct 355 ms 18904 KB Output is correct
41 Correct 105 ms 10620 KB Output is correct
42 Correct 16 ms 2928 KB Output is correct
43 Correct 1123 ms 42036 KB Output is correct
44 Correct 1917 ms 42384 KB Output is correct
45 Correct 683 ms 33956 KB Output is correct
46 Correct 584 ms 35184 KB Output is correct
47 Correct 1235 ms 34736 KB Output is correct
48 Correct 500 ms 41372 KB Output is correct
49 Correct 498 ms 41604 KB Output is correct
50 Correct 505 ms 41788 KB Output is correct
51 Correct 8 ms 1804 KB Output is correct
52 Correct 8 ms 1864 KB Output is correct
53 Correct 9 ms 1812 KB Output is correct
54 Correct 12 ms 1808 KB Output is correct
55 Correct 12 ms 1800 KB Output is correct
56 Correct 11 ms 1804 KB Output is correct
57 Correct 69 ms 14580 KB Output is correct
58 Correct 70 ms 14504 KB Output is correct
59 Correct 74 ms 14328 KB Output is correct
60 Correct 145 ms 13920 KB Output is correct
61 Correct 140 ms 14088 KB Output is correct
62 Correct 153 ms 14132 KB Output is correct
63 Correct 667 ms 12484 KB Output is correct
64 Correct 639 ms 12480 KB Output is correct
65 Correct 666 ms 12456 KB Output is correct
66 Correct 342 ms 13048 KB Output is correct
67 Correct 115 ms 13992 KB Output is correct
68 Correct 143 ms 14024 KB Output is correct
69 Correct 122 ms 14040 KB Output is correct
70 Correct 114 ms 14000 KB Output is correct
71 Correct 113 ms 14044 KB Output is correct
72 Correct 113 ms 13968 KB Output is correct
73 Correct 118 ms 14096 KB Output is correct
74 Correct 111 ms 13996 KB Output is correct
75 Correct 228 ms 43112 KB Output is correct
76 Correct 232 ms 42848 KB Output is correct
77 Correct 243 ms 42996 KB Output is correct
78 Correct 225 ms 42804 KB Output is correct
79 Correct 328 ms 42632 KB Output is correct
80 Correct 224 ms 42732 KB Output is correct
81 Correct 838 ms 42020 KB Output is correct
82 Correct 796 ms 41828 KB Output is correct
83 Correct 789 ms 41760 KB Output is correct
84 Correct 1493 ms 42332 KB Output is correct
85 Correct 843 ms 41844 KB Output is correct
86 Correct 859 ms 41952 KB Output is correct
87 Correct 1138 ms 41980 KB Output is correct
88 Execution timed out 3028 ms 36248 KB Time limit exceeded
89 Halted 0 ms 0 KB -