# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1039449 |
2024-07-30T22:07:12 Z |
Nika533 |
Drzava (COCI15_drzava) |
C++14 |
|
302 ms |
5332 KB |
#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
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 |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
88 ms |
2580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
296 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
302 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
279 ms |
4760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
292 ms |
5264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
262 ms |
5216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
240 ms |
5252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
236 ms |
5288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
198 ms |
5104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
225 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
262 ms |
5316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
245 ms |
5308 KB |
Output is correct |