답안 #413638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413638 2021-05-29T07:08:24 Z hhhhaura 원 고르기 (APIO18_circle_selection) C++14
12 / 100
996 ms 56380 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i ,a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)

using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().times_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	int n;
	vector<int> vis, x, y, r;
	void init_(int _n) {
		n = _n;
		x.assign(n + 1, 0);
		y.assign(n + 1, 0);
		r.assign(n + 1, 0);
		vis.assign(n + 1, 0);
	}
	bool cmp(int a, int b) {
		if(r[a] != r[b]) return r[a] > r[b];
		else return a < b;
	}
	bool comp(int a, int b) {
		int xx = x[a] - x[b];
		int yy = y[a] - y[b];
		int ans = xx * xx + yy * yy;
		int rr = (r[a] + r[b]) * (r[a] + r[b]);
		return ans <= rr;
	}
	void solve() {
		vector<int> ord;
		rep(i, 1, n) ord.push_back(i);
		sort(all(ord), cmp);
		for(auto i : ord) {
			if(vis[i]) continue;
			vis[i] = i;
			rep(j, 1, n) if(!vis[j] && comp(i, j)) vis[j] = i; 
		} 
		rep(i, 1, n) cout << vis[i] << " \n"[i == n];
	}

};
namespace solver1 {
	int n;
	vector<int> vis, x, y, r;
	void init_(int _n) {
		n = _n;
		x.assign(n + 1, 0);
		y.assign(n + 1, 0);
		r.assign(n + 1, 0);
		vis.assign(n + 1, 0);
	}
	bool cmp(int a, int b) {
		if(r[a] != r[b]) return r[a] > r[b];
		else return a < b;
	}
	void solve() {
		vector<int> ord;
		multiset<pii> mp;
		rep(i, 1, n) {
			ord.push_back(i);
			mp.insert({x[i] - r[i], -i});
			mp.insert({x[i] + r[i], i});
		}
		sort(all(ord), cmp);
		for(auto i : ord) if(!vis[i]) {
			auto L = mp.lower_bound({x[i] - r[i], -INF});
			auto R = mp.upper_bound({x[i] + r[i], -INF});
			while(L != mp.end() && L -> first <= x[i] + r[i]) {
				auto cur = L; 
				int id = cur -> second;
				vis[abs(id)] = i;
				auto to = mp.find({cur -> first + (id < 0 ? 1 : -1) * 2 * r[abs(id)], -id});
				mp.erase(to);
				L = next(L);mp.erase(cur);
			}
		}
		rep(i, 1, n) cout << vis[i] << " \n"[i == n];
	}

};
using namespace solver1;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n; cin >> n;
	init_(n);
	rep(i, 1, n) cin >> x[i] >> y[i] >> r[i];
	solve();
	
	return 0;
}

Compilation message

circle_selection.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
circle_selection.cpp:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
circle_selection.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
circle_selection.cpp: In function 'void solver1::solve()':
circle_selection.cpp:89:9: warning: variable 'R' set but not used [-Wunused-but-set-variable]
   89 |    auto R = mp.upper_bound({x[i] + r[i], -INF});
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 974 ms 51776 KB Output is correct
2 Correct 996 ms 51688 KB Output is correct
3 Correct 940 ms 51428 KB Output is correct
4 Correct 973 ms 51788 KB Output is correct
5 Correct 740 ms 51436 KB Output is correct
6 Correct 705 ms 56232 KB Output is correct
7 Correct 761 ms 56380 KB Output is correct
8 Correct 702 ms 56232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 766 ms 51260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -