#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<iomanip>
#define DIM 50005
using namespace std;
int n, k, i;
long long st, dr, mid;
long double r;
int viz[DIM], a[35], b[35];
vector<int> vec[DIM];
set< pair<int, int> > s;
struct str{
int x, y, c;
};
str v[DIM];
int cmp(str a, str b){
if(a.x == b.x){
return a.y < b.y;
}
return a.x < b.x;
}
long long dist(int i, int j){
return (v[i].x - v[j].x) * 1LL * (v[i].x - v[j].x) + (v[i].y - v[j].y) * 1LL * (v[i].y - v[j].y);
}
void dfs(int nod){
int i, vecin;
viz[nod] = 1;
for(i = 0; i < k; i++){
b[i] = a[i];
if(i - v[nod].c >= 0 && a[i - v[nod].c] == 1){
b[i] = 1;
}
if(i - v[nod].c < 0 && a[i - v[nod].c + k] == 1){
b[i] = 1;
}
}
b[ v[nod].c ] = 1;
for(i = 0; i < k; i++){
a[i] = b[i];
}
for(i = 0; i < vec[nod].size(); i++){
vecin = vec[nod][i];
if(viz[vecin] == 0){
dfs(vecin);
}
}
}
int solve(long double d){
int i, j, u, nr;
set< pair<int, int> > :: iterator it;
for(i = 1; i <= n; i++){
vec[i].clear();
viz[i] = 0;
}
u = 1;
for(i = 1; i <= n; i++){
while(v[i].x - v[u].x > d){
s.erase( make_pair(v[u].y, u) );
u++;
}
s.insert( make_pair(v[i].y, i) );
it = s.lower_bound( make_pair(v[i].y, i) );
nr = 0;
while(it != s.begin()){
it--;
if(v[i].y - it->first > d){
break;
}
nr++;
if(nr == 4 * k){
return 1;
}
if( dist(it->second, i) <= d * d ){
vec[i].push_back(it->second);
vec[it->second].push_back(i);
}
}
it = s.lower_bound( make_pair(v[i].y, i) );
it++;
nr = 0;
while(it != s.end()){
if(it->first - v[i].y > d){
break;
}
nr++;
if(nr == 4 * k){
return 1;
}
if( dist(it->second, i) <= d * d ){
vec[i].push_back(it->second);
vec[it->second].push_back(i);
}
it++;
}
}
for(i = n; i >= 1; i--){
if(viz[i] == 0){
for(j = 0; j < k; j++){
a[j] = 0;
}
dfs(i);
if(a[0] == 1){
return 1;
}
}
}
return 0;
}
int main(){
cin>> n >> k;
for(i = 1; i <= n; i++){
cin>> v[i].x >> v[i].y >> v[i].c;
v[i].c %= k;
}
sort(v + 1, v + n + 1, cmp);
st = 10000;
dr = 20000000000000LL;
while(st <= dr){
mid = (st + dr) / 2;
r = mid / 10000.0;
if( solve(r) ){
dr = mid - 1;
}
else{
st = mid + 1;
}
}
if(st % 10 >= 5){
st += 10;
}
st /= 10;
r = st / 1000.0;
cout<< setprecision(3) << fixed << r;
return 0;
}
Compilation message
drzava.cpp: In function 'void dfs(int)':
drzava.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i = 0; i < vec[nod].size(); i++){
~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1576 KB |
Output is correct |
2 |
Correct |
16 ms |
2296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1532 KB |
Output is correct |
2 |
Correct |
11 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
10 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1504 KB |
Output is correct |
2 |
Correct |
14 ms |
2168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1528 KB |
Output is correct |
2 |
Correct |
16 ms |
2296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1500 KB |
Output is correct |
2 |
Correct |
11 ms |
1972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
164 ms |
3536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Execution timed out |
1018 ms |
53960 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Execution timed out |
1072 ms |
53596 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
667 ms |
17648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
730 ms |
20216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
701 ms |
21368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
439 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
556 ms |
13136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
523 ms |
22536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
532 ms |
9784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
437 ms |
7168 KB |
Output is correct |