답안 #1070879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070879 2024-08-22T20:18:21 Z wfe2017 원 고르기 (APIO18_circle_selection) C++14
0 / 100
55 ms 2652 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
 
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
 
const char nl = '\n';
 
void fastIO() {
	ios::sync_with_stdio(false);
	cin.tie(0);
}
 
int main() {
	fastIO();
	int N;
	cin>>N;
	vector<ii> cr(N);
	for (int i = 0; i < N; i++) {
		int x, y, r;
		cin>>x>>y>>r;
		cr[i] = {x, r};
	}
  	if(N > 100000) return 0;
	multiset<ii> lpos;	// {lp, id}
	multiset<ii> rpos;	// {rp, id}
	multiset<ii> have;	// {r, -id]}
	for (int i = 0; i < N; i++) {
		int x = cr[i].fi;
		int r = cr[i].se;
		lpos.insert({x + r, i});
		rpos.insert({x - r, i});
		have.insert({r, -i});
	}
	vi par(N, -1);
	int rem = N;
	while (rem != 0) {
		auto it = --have.end();
		int id = -(*it).se;	// id of current circle
		int x = cr[id].fi;
		int r = cr[id].se;
		int lp = x - r;
		int rp = x + r;
//		cout<<"lp, rp: "<<lp<<" "<<rp<<endl;
		// find all circles with lp[i], rp[i] in [lp, rp]
		set<int> tr;	// id of circles to remove
		auto it2 = lpos.lower_bound({lp, -1});
		while ((it2 != lpos.end()) && ((*it2).fi <= rp)) {
			tr.insert((*it2).se);
			it2++;
		}
		auto it3 = rpos.lower_bound({lp, -1});
		while ((it3 != rpos.end()) && ((*it3).fi <= rp)) {
			tr.insert((*it3).se);
			it3++;
		}
		for (int x : tr) {
			par[x] = id;
			rem--;
			lpos.erase({cr[x].fi - cr[x].se, x});
			rpos.erase({cr[x].fi + cr[x].se, x});
			have.erase({cr[x].se, x});
		}
//		cout<<id<<": "<<rem<<endl;
	}
//	cout<<"ANSWER: ";
	for (int x : par)
		cout<<(x + 1)<<" ";
	cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -