#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define ull unsigned long long
#define pll pair<ll, ll>
#define mp make_pair
#define ll long long
#define pb push_back
#define deb(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define ld long double
const ll mod1 = (ll)1e9 + 7;
const ll mod2 = (ll)1e9 + 9;
const ll BASE = 47;
const ll inf = (ll)1e18;
const long double e = 2.718281828459;
const long double pi = 3.141592653;
const ld EPS = 1e-9;
using namespace std;
template <class T>
istream& operator>>(istream &in, vector<T> &arr) {
for (T &cnt : arr) {
in >> cnt;
}
return in;
};
struct point {
ll x, y;
ll k;
};
ld dist(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
vector<point> arr;
ll n, k;
struct dsu {
vector<ll> pr, sz, used;
vector<vector<ll>> have;
dsu() {
pr.resize(n);
sz.resize(n, 1);
have.resize(n);
used.resize(n, 0);
for (int i = 0; i < n; i++) {
pr[i] = i;
have[i].pb(arr[i].k);
}
}
ll lead(ll x) {
if (pr[x] == x) {
return x;
}
pr[x] = lead(pr[x]);
return pr[x];
}
bool unite(ll a, ll b) {
a = lead(a);
b = lead(b);
if (a == b) {
return false;
}
if (sz[a] < sz[b]) {
swap(a, b);
}
pr[b] = a;
sz[a] += sz[b];
if (sz[a] >= k) {
return true;
}
for (auto i : have[b]) {
have[a].pb(i);
}
return false;
}
bool keks(ll x) {
x = lead(x);
if (used[x] == 1) {
return false;
}
used[x] = 1;
if (sz[x] >= k) {
return true;
}
ll mask = 0;
for (auto i : have[x]) {
mask |= ((mask << i) | (1LL << i));
mask |= (mask >> k);
mask &= (1LL << k) - 1;
}
return (mask & 1);
}
};
bool check(ld d) {
ll l = 0, r = -1;
set<pair<ll, ll>> kek;
dsu ggwp;
for (int i = 0; i < n; i++) {
while (r + 1 < n and abs(arr[r + 1].x - arr[i].x) <= ceil(d)) {
kek.insert({arr[r + 1].y, r + 1});
r++;
}
while (abs(arr[l].x - arr[i].x) > floor(d)) {
kek.erase(kek.find({arr[l].y, l}));
l++;
}
auto it = kek.lower_bound({ceil(arr[i].y - d), -inf});
ll cnt = 0;
while (it != kek.end() and it->first <= floor(arr[i].y + d)) {
cnt++;
if (cnt >= 9 * k) {
return true;
}
if (it->second != i and dist(arr[it->second], arr[i]) <= d) {
if (ggwp.unite(i, it->second)) {
return true;
}
}
it++;
}
}
for (int i = 0; i < n; i++) {
if (ggwp.keks(i)) {
return true;
}
}
return false;
}
void solve() {
cin >> n >> k;
arr.resize(n);
for (int i = 0; i < n; i++) {
cin >> arr[i].x >> arr[i].y >> arr[i].k;
arr[i].k %= k;
}
sort(all(arr), [&](point a, point b) {
return mp(a.x, a.y) < mp(b.x, b.y);
});
ld l = 0, r = 1e9;
while (r - l > EPS) {
ld mid = (l + r) / 2.0;
if (check(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << fixed << setprecision(3) << r;
}
int main() {
#ifndef LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#else
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cout.precision(30);
ll seed = time(0);
//cerr << "Seed: " << seed << "\n";
srand(seed);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
15 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
14 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
14 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
16 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
12 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
300 ms |
4004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
912 ms |
8376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
384 KB |
Output is correct |
2 |
Correct |
921 ms |
8364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
901 ms |
8060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
924 ms |
8608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
866 ms |
8640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
855 ms |
8648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
826 ms |
8628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
766 ms |
8608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
800 ms |
8636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
866 ms |
8644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
831 ms |
8540 KB |
Output is correct |