#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=1,r=1e9,d=0;
while (r-l>=0.00001) {
double mid=(l+r)/2;
if (solve(mid)) {
r=mid-0.00001; d=mid;
}
else l=mid+0.00001;
}
cout<<fixed<<setprecision(3)<<d<<endl;
}
Compilation message
drzava.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
1 | #pragma GCC diagnostic warning "-std=c++11"
| ^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
85 ms |
2560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
280 ms |
6080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
293 ms |
6088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
266 ms |
5832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
290 ms |
6080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
220 ms |
6152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
192 ms |
5988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
186 ms |
5304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
163 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
188 ms |
6152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
219 ms |
6084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
201 ms |
5152 KB |
Output is correct |