#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 long double ld;
#define int long long
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 used[N];
vector<int> g[N];
void dfs(int cur, vector<int> &c) {
// cerr << "dsf " << cur << endl;
c.push_back(C[cur]);
used[cur] = 1;
for (auto t : g[cur]) {
if (!used[t]) {
dfs(t, c);
}
}
}
int dp[N][K];
bool solve(vector<int> c) {
for (int i = 0; i <= (int)c.size(); i++) {
for (int j = 0; j < k; j++) {
dp[i][j] = -N;
}
}
dp[0][0] = 0;
for (int i = 0; i < (int)c.size(); i++) {
for (int j = 0; j < k; j++) {
if (dp[i][j] == -N) continue;
dp[i + 1][(j + c[i]) % k] = max(dp[i + 1][(j + c[i]) % k], dp[i][j] + 1);
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
return dp[(int)c.size()][0] > 0;
}
bool check(int mid_int) {
ld mid = sqrt(mid_int);
// cerr << "mid " << mid << endl;
for (int i = 0; i < n; i++) {
g[i].clear();
by_block[i].clear();
ids[i] = i;
}
vector<pair<int, int>> seen;
for (int i = 0; i < n; i++) {
ids[i] = i;
block[i] = {X[i] / mid, Y[i] / mid};
seen.push_back(block[i]);
}
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 >= 4 * k) {
return true;
}
i = r;
}
sort(seen.begin(), seen.end());
seen.resize(unique(seen.begin(), seen.end()) - seen.begin());
function<int(pair<int, 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;
};
for (int i = 0; i < n; i++) {
by_block[gt(block[i])].push_back(i);
}
// cerr << "hr " << endl;
for (int i = 0; i + 1 < n; i++) {
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int bl_id = gt({block[i].first + dx, block[i].second + dy});
if (bl_id == -1) continue;
for (auto other : by_block[bl_id]) {
if ((X[i] - X[other]) * (X[i] - X[other]) + (Y[i] - Y[other]) * (Y[i] - Y[other]) <= mid_int) {
g[i].push_back(other);
}
}
}
}
}
// cerr << "hr " << endl;
int ans = 0;
fill(used, used + n, 0);
for (int i = 0; i < n; i++) {
if (!used[i]) {
vector<int> c;
dfs(i, c);
// cerr << "c: " << endl;
// for (auto x : c) {
// cerr << x << ' ';
// }
// cerr << endl;
// cerr << "solve " << endl;
ans |= solve(c);
// cerr << "-solve" << endl;
}
}
return (bool)ans;
}
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];
}
int l = 0;
int r = 4e18 + 239;
while (r - l > 1) {
int m = (r + l) >> 1;
if (check(m)) {
r = m;
} else {
l = m;
}
}
// cerr << check(32) << endl;
cout << fixed << setprecision(3);
cout << sqrt(r) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2944 KB |
Output is correct |
2 |
Correct |
8 ms |
2720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
7 ms |
2688 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
35 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Correct |
30 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
20 ms |
3712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2816 KB |
Output is correct |
2 |
Correct |
32 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
31 ms |
4504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2816 KB |
Output is correct |
2 |
Correct |
26 ms |
3712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
866 ms |
18664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Runtime error |
360 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Runtime error |
355 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2816 KB |
Output is correct |
2 |
Runtime error |
382 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Runtime error |
428 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Runtime error |
427 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Execution timed out |
1075 ms |
32220 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Execution timed out |
1091 ms |
41084 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Execution timed out |
1096 ms |
54444 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Execution timed out |
1094 ms |
54600 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Runtime error |
414 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Execution timed out |
1093 ms |
35512 KB |
Time limit exceeded |