Submission #252805

#TimeUsernameProblemLanguageResultExecution timeMemory
252805VEGAnnDrzava (COCI15_drzava)C++14
64 / 160
150 ms8312 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define PB push_back using namespace std; using namespace __gnu_pbds; typedef long double ld; typedef long long ll; const int N = 1010; const int md = 998244353; const int PW = 233; const ld E = 1e-9; const int K = 33; ll dist[N][N]; int n, x[N], y[N], vl[N], pr[N], k; bool mrk[N], ff[K], f[K]; ll sqr(ll x) { return (x * x); } int get(int x) { return (pr[x] == x ? x : pr[x] = get(pr[x])); } bool ok(ll len){ for (int i = 0; i < n; i++) pr[i] = i; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (dist[i][j] <= len){ pr[get(j)] = get(i); } fill(mrk, mrk + n, 0); for (int i = 0; i < n; i++){ int cr = get(i); if (mrk[cr]) continue; mrk[cr] = 1; fill(f, f + K, 0); for (int j = i; j < n; j++){ if (get(j) != cr) continue; fill(ff, ff + K, 0); ff[vl[j]] = 1; for (int it = 0; it < k; it++) if (f[it]) ff[(it + vl[j]) % k] = 1; for (int it = 0; it < k; it++) f[it] |= ff[it]; } if (f[0]) return 1; } return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n >> k; assert(n < N); for (int i = 0; i < n; i++){ cin >> x[i] >> y[i] >> vl[i]; vl[i] %= k; } for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++){ dist[i][j] = dist[j][i] = sqr(x[i] - x[j]) + sqr(y[i] - y[j]); } ll l = 1, r = ll(1e18); while (l < r){ ll md = (l + r) >> 1; if (ok(md)) r = md; else l = md + 1; } cout << fixed << setprecision(3) << sqrt(ld(l)); return 0; }
#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...