Submission #1104587

#TimeUsernameProblemLanguageResultExecution timeMemory
1104587TrinhKhanhDungDrzava (COCI15_drzava)C++14
160 / 160
736 ms56196 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 + 10 #define INF (ll)1e9 #define MOD (ll)(1e9 + 7) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} //DON'T BELIEVE ANYONE WILL INSPIRE YOU -> TRAIN HARDER -> YOU WILL GET WHAT YOU WANT const int MAX = 5e4 + 10; int N, K; array<int, 3> a[MAX]; void input(){ cin >> N >> K; for(int i = 1; i <= N; i++){ int x, y, k; cin >> x >> y >> k; a[i] = {x, y, k}; } } namespace process{ vector<int> adj[MAX]; bool visited[MAX]; bool dp[35], tem[35]; ll dist(array<int, 3> a, array<int, 3> b){ return 1LL * (a[0] - b[0]) * (a[0] - b[0]) + 1LL * (a[1] - b[1]) * (a[1] - b[1]); } void dfs(vector<int> &save, int u){ if(visited[u]) return; visited[u] = true; save.push_back(a[u][2]); for(int v: adj[u]){ dfs(save, v); } } bool OK(ll len){ for(int i = 1; i <= N; i++){ adj[i].clear(); visited[i] = false; } set<pair<int, int>> st; int j = 1; for(int i = 1; i <= N; i++){ while((double)a[j][0] < (double)a[i][0] - sqrt(len)){ st.erase(make_pair(a[j][1], j)); j++; } st.insert(make_pair(a[i][1], i)); int cnt = 0; auto itL = st.lower_bound(pair<int, int>((int)a[i][1] - sqrtl(len), 0)); auto itR = st.upper_bound(pair<int, int>((int)a[i][1] + sqrtl(len), INF)); for(auto it = itL; it != itR; it++){ cnt++; if(cnt >= K * 8) return true; if(dist(a[i], a[it->se]) > len) continue; adj[i].push_back(it->se); adj[it->se].push_back(i); } } for(int i = 1; i <= N; i++) if(!visited[i]){ vector<int> save; dfs(save, i); memset(dp, false, sizeof dp); for(int x: save){ for(int i = 0; i < K; i++){ tem[(i + x) % K] = dp[i]; } dp[x % K] = true; for(int i = 0; i < K; i++){ dp[i] |= tem[i]; } if(dp[0]) return true; } } return false; } } void solve(){ sort(a + 1, a + N + 1); ll l = 1, r = 1e15; while(l < r){ ll m = (l + r) >> 1; if(process::OK(m)) r = m; else l = m + 1; } cout << fixed << setprecision(3) << sqrtl(r) << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("task.inp","r",stdin); // freopen("task.out","w",stdout); input(); solve(); 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...