답안 #516773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516773 2022-01-22T06:05:16 Z pragmatist 원 고르기 (APIO18_circle_selection) C++17
7 / 100
3000 ms 52836 KB
#include <bits/stdc++.h>                             

#define sz(v) v.size()                                
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
 
using namespace std;

typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;

const int N = (int)3e5 + 7;
const int M = (int)15e6 + 7;
const ll MOD = (ll)1e9 + 7;                    
const int inf = (ll)1e9 + 7;
const ll INF = (ll)3e18 + 7;

pii dir[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

int n, x[N], y[N], c[N], a[N];
bool used[N];

bool intersect(int i, int j) {
	int d = c[i] + c[j];
	d *= d;
	int p = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
	return p <= d; 
}

bool ok() {
	for(int i = 1; i <= n; ++i) if(!used[i]) return 0;
	return 1;
}

void solve() {                              
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> x[i] >> y[i] >> c[i];
	if(n <= 5000) {
		while(!ok()) {
			int id = 0;
			for(int i = 1; i <= n; ++i) if(!used[i] && c[i] > c[id]) id = i;
				for(int i = 1; i <= n; ++i) {
				if(!used[i] && intersect(i, id)) a[i] = id, used[i] = 1;
			}			
		}	
	} else {
		set<pii> s;
		for(int i = 1; i <= n; ++i) s.insert({x[i], i});
		while(!s.empty()) {
			int i = (*s.rbegin()).y;
			s.erase({x[i], i});
			for(auto [c, j] : s) {
				if(intersect(i, j)) {
					s.erase({c, j});
					a[j] = i;
				}	
			}	
		}
	}
	for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
}

signed main() {                   
	ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; ++i) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}
/*
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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 166 ms 496 KB Output is correct
23 Correct 166 ms 496 KB Output is correct
24 Correct 161 ms 492 KB Output is correct
25 Correct 156 ms 500 KB Output is correct
26 Correct 152 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 235 ms 52836 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Execution timed out 3081 ms 8920 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3039 ms 26072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 166 ms 496 KB Output is correct
23 Correct 166 ms 496 KB Output is correct
24 Correct 161 ms 492 KB Output is correct
25 Correct 156 ms 500 KB Output is correct
26 Correct 152 ms 504 KB Output is correct
27 Runtime error 6 ms 2168 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 166 ms 496 KB Output is correct
23 Correct 166 ms 496 KB Output is correct
24 Correct 161 ms 492 KB Output is correct
25 Correct 156 ms 500 KB Output is correct
26 Correct 152 ms 504 KB Output is correct
27 Runtime error 235 ms 52836 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -