답안 #978768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978768 2024-05-09T16:18:53 Z Halym2007 원 고르기 (APIO18_circle_selection) C++17
7 / 100
277 ms 18740 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
#define ll long long
#define ff first
#define ss second
#define pii pair <int, int>
int n, jog[N];
bool vis[N];
struct coordinate {
	ll x, y, r, idx;
};
coordinate a[N];

bool intersect (coordinate x, coordinate y) {
	ll a1 = (x.x - y.x) * (x.x - y.x), a2 = (x.y - y.y) * (x.y - y.y), a3 = (x.r + y.r) * (x.r + y.r);
	return (a1 + a2 <= a3);
}

//void cykar (coordinate x) {
//	cout << x.x << " " << x.y << " " << x.r << " " << x.idx << "\n";
//}


bool cmp (coordinate x, coordinate y) {
	if (x.r > y.r) return 1;
	else if (x.r == y.r and x.idx < y.idx) return 1;
	return 0;
}


int main () {
//	freopen ("output.txt", "r", stdin);
	cin >> n;
//	bool sub = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].x >> a[i].y >> a[i].r;
		a[i].idx = i;
//		if (a[i].y != 0) sub = 1;
	}
	sort (a + 1, a + n + 1, cmp);
	if (n <= 5000) {
		for (int i = 1; i <= n; ++i) {
			if (vis[i]) continue;
			jog[a[i].idx] = a[i].idx;	
			for (int j = i + 1; j <= n; ++j) {
				assert (a[i].r > a[j].r or (a[i].r == a[j].r and a[i].idx < a[j].idx));
				if (vis[j]) continue;
				if (intersect (a[i], a[j])) {
					jog[a[j].idx] = a[i].idx;
					vis[j] = 1;
				}
			}
		}
	}
	else {
		set <ll> s;
		map <ll, ll> val;
		for (int i = 1; i <= n; ++i) {
			ll l = a[i].x - a[i].r, r = a[i].x + a[i].r;
			if (i == 1) {
				s.insert (l);
				s.insert (r);
				val[l] = a[i].idx;
				val[r] = a[i].idx;
				
				jog[a[i].idx] = a[i].idx;
			}
			else {
				auto tr = s.lower_bound (l);
				if (tr != s.end()) {
					ll x = *tr;
					if (x <= r) {
						jog[a[i].idx] = val[x];
						continue;
					}
					else if (tr != s.begin()) {
						tr--;
						ll y = *tr;
						if (y <= l and r <= x) {
							jog[a[i].idx] = val[x];
							continue;
						}
					}
				}
				s.insert (l);
				s.insert (r);
				val[l] = a[i].idx;
				val[r] = a[i].idx;
				jog[a[i].idx] = a[i].idx;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << jog[i] << " ";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 444 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 6 ms 604 KB Output is correct
20 Correct 6 ms 904 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 22 ms 736 KB Output is correct
23 Correct 23 ms 604 KB Output is correct
24 Correct 23 ms 604 KB Output is correct
25 Correct 23 ms 748 KB Output is correct
26 Correct 28 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 268 ms 18740 KB Output is correct
2 Incorrect 265 ms 18652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 99 ms 10048 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 277 ms 18548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 444 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 6 ms 604 KB Output is correct
20 Correct 6 ms 904 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 22 ms 736 KB Output is correct
23 Correct 23 ms 604 KB Output is correct
24 Correct 23 ms 604 KB Output is correct
25 Correct 23 ms 748 KB Output is correct
26 Correct 28 ms 652 KB Output is correct
27 Incorrect 13 ms 4952 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 444 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 6 ms 604 KB Output is correct
20 Correct 6 ms 904 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 22 ms 736 KB Output is correct
23 Correct 23 ms 604 KB Output is correct
24 Correct 23 ms 604 KB Output is correct
25 Correct 23 ms 748 KB Output is correct
26 Correct 28 ms 652 KB Output is correct
27 Correct 268 ms 18740 KB Output is correct
28 Incorrect 265 ms 18652 KB Output isn't correct
29 Halted 0 ms 0 KB -