This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
using namespace std;
const int N=50005,K=35;
int n,k,sz[N],p[N],val[N];
double x[N],y[N];
vector<pair<double,double>> point;
void make_set(int v) {
p[v]=v; sz[v]=1;
}
int find_set(int v) {
if (p[v]==v) return v;
return p[v]=find_set(p[v]);
}
void merge_set(int a, int b) {
a=find_set(a); b=find_set(b);
if (a==b) return;
if (sz[a]<sz[b]) swap(a,b);
p[b]=a; sz[a]+=sz[b];
}
double dist(int a, int b) {
return abs(x[a]-x[b])*abs(x[a]-x[b])+abs(y[a]-y[b])*abs(y[a]-y[b]);
}
bool solve(double d) {
for (int i=1; i<=n; i++) make_set(i);
set<pair<double,double>> cur;
int l=1;
for (int r=1; r<=n; r++) {
int ind=point[r].second; cur.insert({y[ind],ind});
while (l<r && point[r].first-d>point[l].first) {
int indl=point[l].second; cur.erase({y[indl],indl}); l++;
}
auto it1=cur.lower_bound({y[ind]-d,0}),it2=cur.upper_bound({y[ind]+d,1e9});
for (auto it=it1; it!=it2; it++) {
int ind2=(*it).second;
if (dist(ind,ind2)<=d*d) merge_set(ind,ind2);
if (sz[find_set(ind)]>=k) return true;
}
}
vector<bool> is_root(n+1,false);
vector<int> comp[n+1];
for (int i=1; i<=n; i++) {
is_root[find_set(i)]=true; comp[find_set(i)].push_back(i);
}
for (int i=1; i<=n; i++) {
if (!is_root[i]) continue;
int s=comp[i].size();
bool dp[s][k];
for (int j=0; j<s; j++) {
for (int o=0; o<k; o++) dp[j][o]=false;
}
dp[0][val[comp[i][0]]%k]=true;
for (int j=1; j<s; j++) {
dp[j][val[comp[i][j]]%k]=true;
for (int o=0; o<k; o++) {
if (dp[j-1][o]) {
dp[j][(o+val[comp[i][j]])%k]=true;
dp[j][o]=true;
}
}
}
if (dp[s-1][0]) return true;
}
return false;
}
int main() {
cin>>n>>k; point.emplace_back(0,0);
for (int i=1; i<=n; i++) {
cin>>x[i]>>y[i]>>val[i]; point.emplace_back(x[i],i);
}
sort(point.begin(),point.end());
double l=0,r=1e9,d=0;
while (r-l>=0.000001) {
double mid=(l+r)/2;
if (solve(mid)) {
r=mid-0.000001; d=mid;
}
else l=mid+0.000001;
}
cout<<fixed<<setprecision(3)<<d<<endl;
}
Compilation message (stderr)
drzava.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
1 | #pragma GCC diagnostic warning "-std=c++11"
| ^~~~~~~~~~~~
# | 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... |