Submission #68057

#TimeUsernameProblemLanguageResultExecution timeMemory
68057forestryksDrzava (COCI15_drzava)C++14
136 / 160
1088 ms62552 KiB
/////////////////////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> using namespace std; // #define int long long #define mp make_pair #define pb push_back #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout) #define f first #define s second #define x1 x1qwer #define y1 y1qwer #define right right123 #define left left123 #define foreach(it, v) for (auto it : v) #define rep(it, n) for (int it = 0; it < n; ++it) #define forin(it, l, r) for (int it = l; it < r; ++it) #define all(x) x.begin(), x.end() typedef long long ll; typedef unsigned long long ull; typedef double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const double DINF = numeric_limits<double>::infinity(); const ll MOD = 1e9 + 7; const double EPS = 1e-7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } mt19937 mmtw_(MOD); uniform_int_distribution<ll> rd_; ll randomll() { return rd_(mmtw_);} ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; } template <class T> T fact(T n) { if (n == 1) return 1; return n * fact(n - 1); } //////////////////////////////////////////////////////////////////////////////////////////////// inline ll sqr(ll x) { return x * x; } const int MAXN = 50005; struct city { long long x, y; int k; friend bool operator<(const city &a, const city &b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } } a[MAXN]; inline ll dist(int i, int j) { return sqr(a[i].x - a[j].x) + sqr(a[i].y - a[j].y); } struct cmp { bool operator()(const int &i, const int &j) { if (a[i].y == a[j].y) return i < j; return a[i].y < a[j].y; } }; int n, k; vector<int> g[MAXN]; set<int, cmp> s; int dp[MAXN]; bool used[MAXN]; inline int mod(ll x) { if (x >= k) return x - k; return x; } void dfs(int v) { used[v] = true; if (dp[a[v].k] == -1) dp[a[v].k] = v; for (int i = 0; i < k; ++i) { if (dp[i] != -1 && dp[i] != v) { if (dp[mod(i + a[v].k)] == -1) dp[mod(i + a[v].k)] = v; } } for (auto to : g[v]) { if (!used[to]) dfs(to); } } bool findSet() { fill(used, used + n, false); for (int i = 0; i < n; ++i) { if (used[i]) continue; fill(dp, dp + k, -1); dp[a[i].k] = i; dfs(i); if (dp[0] != -1) return true; } return false; } bool check(ll d) { ll ds = sqrt(d) + 1; for (int i = 0; i < n; ++i) { g[i].clear(); } s.clear(); int left = 0; for (int i = 0; i < n; ++i) { while (sqr(a[i].x - a[left].x) > d) { s.erase(left++); } if (!s.empty()) { a[n].y = a[i].y - ds; int cnt = 0; for (auto it = s.lower_bound(n); it != s.end(); ++it) { int id = *it; if (a[id].y > a[i].y + ds) break; if (++cnt >= k * 8) return true; if (dist(i, id) <= d) { g[i].push_back(id); g[id].push_back(i); } } } s.insert(i); } // rep(v, n) { // for (auto to : g[v]) { // cout << "Segment " << a[v].x << ' ' << a[v].y << ' ' << a[to].x << ' ' << a[to].y << '\n'; // } // } return findSet(); } int main() { FAST_IO; cin >> n >> k; rep(i, n) { cin >> a[i].x >> a[i].y >> a[i].k; a[i].k %= k; } sort(a, a + n); // check(4); ll e18 = 1e18; ll l = -1, r = e18; while (r - l > 1) { ll m = l + (r - l) / 2; if (check(m)) { r = m; } else { l = m; } } if (r == e18) { // cout << -1 << endl; cout << "No solution!" << endl; } else { cout.precision(3); cout.setf(ios::fixed); cout << sqrt(r) << endl; } }
#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...