This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/***************************************************************************/
/********************** LANG TU HAO HOA **********************************/
/***************************************************************************/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define sz(x) ((int) x.size())
#define PB push_back
#define PF push_front
#define MP make_pair
#define ll long long
#define F first
#define S second
#define maxc 1000000007
#define MOD 1000000007
#define base 107
#define eps 1e-6
#define pi acos(-1)
#define N 50004
#define task ""
#define remain(x) ((x > MOD) ? (x - MOD) : x)
using namespace std;
void inline MIN(int &a, int b) {a = min(a, b);}
struct Point
{
int x, y, k;
bool operator < (const Point &B)
{
return x < B.x;
}
} a[N];
int n, K, dp[N][33];
bool dd[N];
vector <int> ke[N];
void Enter()
{
cin >> n >> K;
FOR(i, 1, n)
{
cin >> a[i].x >> a[i].y >> a[i].k;
a[i].k %= K;
}
sort(a+1, a+n+1);
}
double Dist(pii a, pii b)
{
return (double)sqrt(1ll*(a.F-b.F)*(a.F-b.F) + 1ll*(a.S-b.S)*(a.S-b.S));
}
void DFS(int u, vector <int> &kVals)
{
dd[u] = 1;
kVals.PB(a[u].k);
for (auto v : ke[u])
{
if (dd[v]) continue;
DFS(v, kVals);
}
}
bool Divisible(vector <int> &kVals)
{
FOR(i, 0, sz(kVals)+1)
FOR(k, 0, K) dp[i][k] = 0;
dp[0][0] = 1;
FOR(i, 0, sz(kVals))
FOR(k, 0, K)
{
MIN(dp[i+1][k] += dp[i][k], 3);
MIN(dp[i+1][(k+kVals[i])%K] += dp[i][k], 3);
}
return (dp[sz(kVals)][0] > 1);
}
bool CheckGraph()
{
fill(dd+1, dd+n+1, 0);
FOR(i, 1, n)
{
if (dd[i]) continue;
vector <int> kVals;
DFS(i, kVals);
if (sz(kVals) >= K || Divisible(kVals)) return 1;
}
return 0;
}
bool Check(ll sqD)
{
double D = (double)sqrt(sqD) + eps;
set <pair <pii, int> > Built;
for (int i = 1, j = 1; i <= n; ++i)
{
ke[i].clear();
while (j < i && a[i].x - a[j].x > D)
{
Built.erase(MP(MP(a[j].y, a[j].x), j));
j++;
}
if (!Built.empty())
{
for (auto it = Built.lower_bound(MP(MP(a[i].y - D, -1), -1)); it != Built.end() && it->F.F <= a[i].y + D; ++it)
{
double distance = Dist(it->F, MP(a[i].y, a[i].x));
if (distance <= D)
{
ke[i].PB(it->S);
ke[it->S].PB(i);
}
if (sz(ke[i]) >= K) return 1;
}
}
Built.insert(MP(MP(a[i].y, a[i].x), i));
}
return CheckGraph();
}
void Produce()
{
ll l = 0, r = 2e16+1;
while (r - l > 1)
{
ll mid = (l + r) >> 1;
if (Check(mid)) r = mid;
else l = mid;
}
cout << fixed << setprecision(3) << sqrt(r);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
Enter();
Produce();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |