답안 #745032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745032 2023-05-19T10:22:52 Z b00norp 원 고르기 (APIO18_circle_selection) C++14
7 / 100
3000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18, N = 3e5 + 5;
vector<int> g[N];
bool vis[N];

bool cmp(array<int, 2> a, array<int, 2> b)
{
	if(a[0] != b[0])
	{
		return a[0] > b[0];
	}
	return a[1] < b[1];
}

void Solve() 
{
	int n;
	cin >> n;
	vector<array<int, 3> > circle(n + 1);
	for(int i = 1; i <= n; i++)
	{
		cin >> circle[i][0] >> circle[i][1] >> circle[i][2];
	}
	vector<array<int, 2> > order;
	for(int i = 1; i <= n; i++)
	{
		order.push_back({circle[i][2], i});
		for(int j = i + 1; j <= n; j++)
		{
			int x = abs(circle[i][0] - circle[j][0]), y = abs(circle[i][1] - circle[j][1]);
			int dist = x * x + y * y;
			if(dist <= (circle[i][2] + circle[j][2]) * (circle[i][2] + circle[j][2]))
			{
				g[i].push_back(j);
				g[j].push_back(i);
			}
		}
	}
	sort(order.begin(), order.end(), cmp);
	vector<int> res(n + 1, -1);
	for(int i = 0; i < order.size(); i++)
	{
		int idx = order[i][1];
		if(vis[idx]) continue;
		vis[idx] = true;
		res[idx] = idx;
		for(int j: g[idx])
		{
			if(!vis[j])
			{
				vis[j] = true;
				res[j] = idx;
			}
		}
	}
	for(int i = 1; i <= n; i++)
	{
		cout << res[i] << " ";
	}
	cout << "\n";
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}

/*
Sample 1:
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1

*/

Compilation message

circle_selection.cpp: In function 'void Solve()':
circle_selection.cpp:46:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int i = 0; i < order.size(); i++)
      |                 ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 4 ms 7508 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 15 ms 15828 KB Output is correct
17 Correct 15 ms 15456 KB Output is correct
18 Correct 16 ms 16096 KB Output is correct
19 Correct 263 ms 261736 KB Output is correct
20 Correct 263 ms 262476 KB Output is correct
21 Correct 229 ms 164824 KB Output is correct
22 Correct 47 ms 7836 KB Output is correct
23 Correct 44 ms 7752 KB Output is correct
24 Correct 46 ms 7916 KB Output is correct
25 Correct 44 ms 7800 KB Output is correct
26 Correct 47 ms 7756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2343 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7376 KB Output is correct
2 Execution timed out 3060 ms 12956 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3034 ms 22524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 4 ms 7508 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 15 ms 15828 KB Output is correct
17 Correct 15 ms 15456 KB Output is correct
18 Correct 16 ms 16096 KB Output is correct
19 Correct 263 ms 261736 KB Output is correct
20 Correct 263 ms 262476 KB Output is correct
21 Correct 229 ms 164824 KB Output is correct
22 Correct 47 ms 7836 KB Output is correct
23 Correct 44 ms 7752 KB Output is correct
24 Correct 46 ms 7916 KB Output is correct
25 Correct 44 ms 7800 KB Output is correct
26 Correct 47 ms 7756 KB Output is correct
27 Correct 1065 ms 736424 KB Output is correct
28 Correct 1123 ms 909656 KB Output is correct
29 Correct 1179 ms 876580 KB Output is correct
30 Correct 158 ms 8184 KB Output is correct
31 Correct 159 ms 8212 KB Output is correct
32 Correct 165 ms 8336 KB Output is correct
33 Runtime error 1849 ms 1048576 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 4 ms 7508 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 15 ms 15828 KB Output is correct
17 Correct 15 ms 15456 KB Output is correct
18 Correct 16 ms 16096 KB Output is correct
19 Correct 263 ms 261736 KB Output is correct
20 Correct 263 ms 262476 KB Output is correct
21 Correct 229 ms 164824 KB Output is correct
22 Correct 47 ms 7836 KB Output is correct
23 Correct 44 ms 7752 KB Output is correct
24 Correct 46 ms 7916 KB Output is correct
25 Correct 44 ms 7800 KB Output is correct
26 Correct 47 ms 7756 KB Output is correct
27 Runtime error 2343 ms 1048576 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -