#ifndef LOCAL
#pragma GCC optimize("Ofast")
#endif
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
using namespace std;
typedef double ld;
typedef long long ll;
const int N = 5e4;
const int K = 30;
int n, k;
int X[N];
int Y[N];
int C[N];
int ids[N];
pair<int, int> block[N];
vector<int> by_block[N];
int block_ind[N];
int bl_ids[N][3][3];
int used[N];
int dp[2][K];
void dfs(int i, ll mid_int, int &ret) {
used[i] = 1;
{
for (int j = 0; j < k; j++) {
if (dp[0][j] == -N) continue;
dp[1][(j + C[i]) % k] = max(dp[1][(j + C[i]) % k], dp[0][j] + 1);
dp[1][j] = max(dp[1][j], dp[0][j]);
}
for (int j = 0; j < k; j++) {
dp[0][j] = dp[1][j];
dp[1][j] = -N;
}
if (dp[0][0] > 0) ret = 1;
}
if (ret) return;
int we = block_ind[i];
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int bl_id = bl_ids[we][dx + 1][dy + 1];
if (bl_id == -1) continue;
for (auto other : by_block[bl_id]) {
if (ret) break;
if (!used[other] && (ll)(X[i] - X[other]) * (X[i] - X[other]) + (ll)(Y[i] - Y[other]) * (Y[i] - Y[other]) <= mid_int) {
dfs(other, mid_int, ret);
}
if (ret) break;
}
if (ret) break;
}
if (ret) break;
}
}
vector<pair<int, int>> seen;
int gt(pair<int, int> v) {
auto it = lower_bound(seen.begin(), seen.end(), v);
if (it != seen.end() && *it == v) {
return (int)(it - seen.begin());
}
return (int)-1;
};
bool check(ll mid_int) {
{
ld mid = sqrt((ld)mid_int / 2);
for (int i = 0; i < n; i++) {
ids[i] = i;
block[i] = {X[i] / mid, Y[i] / mid};
}
sort(ids, ids + n, [&](int i, int j) {
return block[i] < block[j];
});
for (int i = 0; i < n; i++) {
int r = i;
while (r + 1 < n && block[ids[r]] == block[ids[r + 1]]) {
r++;
}
if (r - i + 1 >= k) {
return true;
}
i = r;
}
}
{
ld mid = sqrt((ld)mid_int);
seen.clear();
for (int i = 0; i < n; i++) {
ids[i] = i;
block[i] = {X[i] / mid, Y[i] / mid};
seen.push_back(block[i]);
by_block[i].clear();
}
sort(ids, ids + n, [&](int i, int j) {
return block[i] < block[j];
});
}
{
int c = 0;
for (int i = 0; i < n; i++) {
if (i > 0) c += (block[ids[i - 1]] < block[ids[i]]);
block_ind[ids[i]] = c;
by_block[c].push_back(ids[i]);
}
}
sort(seen.begin(), seen.end());
seen.resize(unique(seen.begin(), seen.end()) - seen.begin());
for (int i = 0; i < (int)seen.size(); i++) {
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
bl_ids[i][dx + 1][dy + 1] = gt({seen[i].first + dx, seen[i].second + dy});
}
}
}
fill(used, used + n, 0);
for (int i = 0; i < n; i++) {
if (!used[i]) {
fill(dp[0], dp[0] + k, -N);
fill(dp[1], dp[1] + k, -N);
dp[0][0] = 0;
int ret = 0;
dfs(i, mid_int, ret);
if (ret) return true;
}
}
return false;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> X[i] >> Y[i] >> C[i];
}
ll r = 4e16 + 239;
for (int i = 60; i >= 0; i--) {
if (r > (1LL << i) && check(r - (1LL << i))) r -= (1LL << i);
}
cout << fixed << setprecision(3);
cout << sqrt(r) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
5 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
6 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
12 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
18 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1536 KB |
Output is correct |
2 |
Correct |
18 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
11 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
13 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
17 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
179 ms |
3960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
519 ms |
6772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
907 ms |
6672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1664 KB |
Output is correct |
2 |
Correct |
475 ms |
6516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
514 ms |
6864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
505 ms |
6864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
483 ms |
6932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1536 KB |
Output is correct |
2 |
Correct |
506 ms |
6900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1536 KB |
Output is correct |
2 |
Correct |
393 ms |
7028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1536 KB |
Output is correct |
2 |
Correct |
411 ms |
6876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
511 ms |
6972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1408 KB |
Output is correct |
2 |
Correct |
438 ms |
6876 KB |
Output is correct |