This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 50500;
const int K = 35;
int n, k;
int x[N], y[N], z[N];
int p[N];
int find(int x) {
if (x == p[x]) return x;
return p[x] = find(p[x]);
}
void unia(int x, int y) {
p[find(x)] = find(y);
}
vector <int> points, v[N];
set <pair<int, int>> s; // {y, indeks}
LL dis(int a, int b) {
return (LL) (x[a] - x[b]) * (x[a] - x[b]) + (LL) (y[a] - y[b]) * (y[a] - y[b]);
}
int dp[K][2];
bool ok(LD d) {
rep(i, 1, n) {
p[i] = i;
v[i].clear();
}
s.clear();
int j = 0;
LD D = d * d;
rep(i, 0, n - 1) {
int ID = points[i];
int X = x[ID];
int Y = y[ID];
while (X - x[points[j]] > d) {
s.erase({y[points[j]], points[j]});
j++;
}
int f = 0;
auto it = s.lower_bound(mp(Y - floor(d), -1));
while (it != s.end() && it->fi <= Y + d) {
if (dis(ID, it->se) <= D) unia(ID, it->se);
it++;
f++;
if (f >= 8 * k) return true;
}
s.insert({Y, ID});
}
rep(i, 1, n) v[find(i)].pb(i);
rep(i, 1, n) {
if (v[i].empty()) continue;
rep(j, 0, k - 1) dp[j][0] = 0;
for (auto it : v[i]) {
rep(j, 0, k - 1) dp[j][1] = dp[j][0];
dp[z[it]][1] = 1;
rep(j, 0, k - 1) dp[(j + z[it]) % k][1] |= dp[j][0];
rep(j, 0, k - 1) dp[j][0] = dp[j][1];
}
if (dp[0][0] == 1) return true;
}
return false;
}
int main() {
scanf ("%d%d", &n, &k);
rep(i, 1, n) {
scanf ("%d%d%d", x + i, y + i, z + i);
z[i] %= k;
points.pb(i);
}
sort(points.begin(), points.end(), [](int a, int b) {
return x[a] < x[b];
});
LD L = 0.0, R = 1e9 + 100;
rep(i, 1, 50) {
LD M = (L + R) / 2;
if (ok(M)) R = M;
else L = M;
}
printf("%.3Lf\n", L);
return 0;
}
Compilation message (stderr)
drzava.cpp: In function 'int main()':
drzava.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n, &k);
~~~~~~^~~~~~~~~~~~~~~~
drzava.cpp:89:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d", x + i, y + i, z + i);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |