Submission #580595

# Submission time Handle Problem Language Result Execution time Memory
580595 2022-06-21T13:22:34 Z vovamr Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 88084 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

#define int long long
#define sqr(x) ((x)*1ll*(x))
struct cir { int x, y, r, id; };
inline int ds(const cir &a, const cir &b) { return sqr(a.x-b.x)+sqr(a.y-b.y); }
inline bool isec(const cir &a, const cir &b) { return ds(a, b) <= sqr(a.r + b.r); }
inline bool operator < (const cir &a, const cir &b) {
	if (a.r != b.r) return a.r > b.r;
	else if (a.id != b.id) return a.id < b.id;
	else if (a.x != b.x) return a.x < b.x;
	else return a.y < b.y;
}

inline void solve() {
	int n;
	cin >> n;

	set<cir> st;
	for (int i = 0; i < n; ++i) {
		int x, y, r;
		cin >> x >> y >> r;
		st.insert(cir{x, y, r, i});
	}

	ve<int> ans(n);

	int R = 2e9;

	map<pii,set<cir>> mp;
	auto ins = [&mp,&R](const cir &a) { mp[mpp(a.x / R, a.y / R)].insert(a); };
	auto ers = [&mp,&R](const cir &a) { mp[mpp(a.x / R, a.y / R)].erase(a); };

	while (sz(st)) {

		auto x = *st.begin();
		st.erase(st.begin());
		ers(x);

		ans[x.id] = x.id;

		if (x.r <= R / 2) { R = x.r; mp.clear(); for (auto &f : st) ins(f); }

		int a = x.x / R, b = x.y / R;

		ve<cir> bad;
		for (int i = -2; i <= 2; ++i) {
			for (int j = -2; j <= 2; ++j) {
				if (!mp.count(mpp(a + i, b + j))) continue;

				for (auto &cr : mp[mpp(a + i, b + j)]) {
					if (isec(x, cr)) {
						ans[cr.id] = x.id;
						bad.pb(cr);
					}
				}
			}
		}

		for (auto &f : bad) {
			st.erase(f);
			ers(f);
		}
	}

	for (auto i : ans) cout << i + 1 << " ";
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 1492 KB Output is correct
20 Correct 5 ms 1492 KB Output is correct
21 Correct 7 ms 1324 KB Output is correct
22 Correct 15 ms 1612 KB Output is correct
23 Correct 15 ms 1620 KB Output is correct
24 Correct 13 ms 1612 KB Output is correct
25 Correct 14 ms 1620 KB Output is correct
26 Correct 15 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 512 ms 66116 KB Output is correct
2 Correct 633 ms 62508 KB Output is correct
3 Correct 584 ms 58084 KB Output is correct
4 Correct 526 ms 66176 KB Output is correct
5 Correct 868 ms 52072 KB Output is correct
6 Correct 1131 ms 70132 KB Output is correct
7 Correct 976 ms 57908 KB Output is correct
8 Correct 967 ms 60220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 603 ms 26648 KB Output is correct
3 Correct 2232 ms 87824 KB Output is correct
4 Correct 2257 ms 87840 KB Output is correct
5 Correct 2145 ms 81140 KB Output is correct
6 Correct 862 ms 42200 KB Output is correct
7 Correct 341 ms 22456 KB Output is correct
8 Correct 49 ms 4968 KB Output is correct
9 Correct 2500 ms 87196 KB Output is correct
10 Correct 2177 ms 80948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1683 ms 79728 KB Output is correct
2 Correct 1222 ms 86808 KB Output is correct
3 Correct 961 ms 67752 KB Output is correct
4 Correct 1253 ms 87144 KB Output is correct
5 Correct 1240 ms 87376 KB Output is correct
6 Correct 806 ms 61012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 1492 KB Output is correct
20 Correct 5 ms 1492 KB Output is correct
21 Correct 7 ms 1324 KB Output is correct
22 Correct 15 ms 1612 KB Output is correct
23 Correct 15 ms 1620 KB Output is correct
24 Correct 13 ms 1612 KB Output is correct
25 Correct 14 ms 1620 KB Output is correct
26 Correct 15 ms 1620 KB Output is correct
27 Correct 11 ms 2564 KB Output is correct
28 Correct 11 ms 2624 KB Output is correct
29 Correct 10 ms 2512 KB Output is correct
30 Correct 32 ms 2912 KB Output is correct
31 Correct 30 ms 2900 KB Output is correct
32 Correct 32 ms 2880 KB Output is correct
33 Correct 129 ms 20924 KB Output is correct
34 Correct 143 ms 20904 KB Output is correct
35 Correct 155 ms 20972 KB Output is correct
36 Correct 560 ms 26664 KB Output is correct
37 Correct 481 ms 29292 KB Output is correct
38 Correct 538 ms 29364 KB Output is correct
39 Correct 922 ms 26492 KB Output is correct
40 Correct 944 ms 26440 KB Output is correct
41 Correct 882 ms 26296 KB Output is correct
42 Correct 401 ms 28248 KB Output is correct
43 Correct 347 ms 29012 KB Output is correct
44 Correct 342 ms 29064 KB Output is correct
45 Correct 328 ms 29136 KB Output is correct
46 Correct 372 ms 29128 KB Output is correct
47 Correct 340 ms 29084 KB Output is correct
48 Correct 353 ms 29200 KB Output is correct
49 Correct 342 ms 29072 KB Output is correct
50 Correct 338 ms 29052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 1492 KB Output is correct
20 Correct 5 ms 1492 KB Output is correct
21 Correct 7 ms 1324 KB Output is correct
22 Correct 15 ms 1612 KB Output is correct
23 Correct 15 ms 1620 KB Output is correct
24 Correct 13 ms 1612 KB Output is correct
25 Correct 14 ms 1620 KB Output is correct
26 Correct 15 ms 1620 KB Output is correct
27 Correct 512 ms 66116 KB Output is correct
28 Correct 633 ms 62508 KB Output is correct
29 Correct 584 ms 58084 KB Output is correct
30 Correct 526 ms 66176 KB Output is correct
31 Correct 868 ms 52072 KB Output is correct
32 Correct 1131 ms 70132 KB Output is correct
33 Correct 976 ms 57908 KB Output is correct
34 Correct 967 ms 60220 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 603 ms 26648 KB Output is correct
37 Correct 2232 ms 87824 KB Output is correct
38 Correct 2257 ms 87840 KB Output is correct
39 Correct 2145 ms 81140 KB Output is correct
40 Correct 862 ms 42200 KB Output is correct
41 Correct 341 ms 22456 KB Output is correct
42 Correct 49 ms 4968 KB Output is correct
43 Correct 2500 ms 87196 KB Output is correct
44 Correct 2177 ms 80948 KB Output is correct
45 Correct 1683 ms 79728 KB Output is correct
46 Correct 1222 ms 86808 KB Output is correct
47 Correct 961 ms 67752 KB Output is correct
48 Correct 1253 ms 87144 KB Output is correct
49 Correct 1240 ms 87376 KB Output is correct
50 Correct 806 ms 61012 KB Output is correct
51 Correct 11 ms 2564 KB Output is correct
52 Correct 11 ms 2624 KB Output is correct
53 Correct 10 ms 2512 KB Output is correct
54 Correct 32 ms 2912 KB Output is correct
55 Correct 30 ms 2900 KB Output is correct
56 Correct 32 ms 2880 KB Output is correct
57 Correct 129 ms 20924 KB Output is correct
58 Correct 143 ms 20904 KB Output is correct
59 Correct 155 ms 20972 KB Output is correct
60 Correct 560 ms 26664 KB Output is correct
61 Correct 481 ms 29292 KB Output is correct
62 Correct 538 ms 29364 KB Output is correct
63 Correct 922 ms 26492 KB Output is correct
64 Correct 944 ms 26440 KB Output is correct
65 Correct 882 ms 26296 KB Output is correct
66 Correct 401 ms 28248 KB Output is correct
67 Correct 347 ms 29012 KB Output is correct
68 Correct 342 ms 29064 KB Output is correct
69 Correct 328 ms 29136 KB Output is correct
70 Correct 372 ms 29128 KB Output is correct
71 Correct 340 ms 29084 KB Output is correct
72 Correct 353 ms 29200 KB Output is correct
73 Correct 342 ms 29072 KB Output is correct
74 Correct 338 ms 29052 KB Output is correct
75 Correct 674 ms 75448 KB Output is correct
76 Correct 641 ms 70760 KB Output is correct
77 Correct 527 ms 75084 KB Output is correct
78 Correct 495 ms 75256 KB Output is correct
79 Correct 897 ms 60780 KB Output is correct
80 Correct 533 ms 75348 KB Output is correct
81 Correct 2222 ms 87792 KB Output is correct
82 Correct 2011 ms 87756 KB Output is correct
83 Correct 2063 ms 87676 KB Output is correct
84 Correct 2270 ms 88084 KB Output is correct
85 Correct 2200 ms 87776 KB Output is correct
86 Correct 2080 ms 87756 KB Output is correct
87 Correct 2241 ms 87632 KB Output is correct
88 Execution timed out 3064 ms 77072 KB Time limit exceeded
89 Halted 0 ms 0 KB -