Submission #47820

#TimeUsernameProblemLanguageResultExecution timeMemory
47820tieunhiDrzava (COCI15_drzava)C++14
136 / 160
1090 ms63912 KiB
#include <bits/stdc++.h> #define PB push_back #define N 50005 #define eps 1e-5 using namespace std; using db = double; int n, k, dp[N][31], curTime, dd[N]; vector<int> g[N], component; struct Point { db x, y; int sz; Point(db _x=0, db _y=0, int _sz=0) : x(_x), y(_y), sz(_sz) {} friend bool operator < (const Point& a, const Point& b) { return a.x < b.x; } Point operator + (Point P) const { return {x + P.x, y + P.y, sz + P.sz}; } Point operator - (Point P) const { return {x - P.x, y - P.y, sz - P.sz}; } db operator % (Point P) const { return x*P.x + y*P.y; } }a[N]; db dist(Point u, Point v) { u = u - v; return sqrt(u%u); } struct cmp { bool operator () (const int &p, const int &q) { if (a[p].y != a[q].y) return a[p].y < a[q].y; return p > q; } }; set<int, cmp> s; void DFS(int u) { dd[u] = curTime; component.PB(u); for (auto v : g[u]) { if (dd[v] == curTime) continue; DFS(v); } } bool exist() { int m = component.size(); if (m > k) return 1; for (int i = 0; i <= m; i++) for (int j = 0; j < k; j++) dp[i][j] = 0; dp[0][0] = 1; for (int i = 0; i < m; i++) for (int j = 0; j < k; j++) { dp[i+1][(a[component[i]].sz + j) % k] |= dp[i][j]; dp[i+1][j] |= dp[i][j]; } for (int i = 0; i < m; i++) for (int j = 0; j < k; j++) if ((j + a[component[i]].sz) % k == 0 && dp[i][j]) return 1; return 0; } bool check(db D) { for (int i = 1; i <= n; i++) g[i].clear(); s.clear(); int cur = 1; for (int i = 1; i <= n; i++) { while (cur < i && a[i].x - a[cur].x > D) s.erase(cur++); if (s.empty()) { s.insert(i); continue; } a[0] = Point(a[i].x, a[i].y - D, 0); int cnt = 0; for (auto it = s.lower_bound(0); it != s.end(); it++) { int idx = *it; if (a[idx].y - a[i].y > D) break; if (++cnt >= 8*k) return 1; if (dist(a[idx], a[i]) <= D) { g[i].PB(idx); g[idx].PB(i); } } s.insert(i); } curTime++; for (int i = 1; i <= n; i++) if (dd[i] != curTime) { component.clear(); DFS(i); if (exist()) return 1; } return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("INP.TXT", "r", stdin); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].sz, a[i].sz %= k; sort(a+1, a+n+1); db l = 0, r = 1e9; while (r - l > eps) { db mid = (r + l)/2; if (check(mid)) r = mid; else l = mid; } cout <<fixed<<setprecision(3)<<r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...