Submission #1104587

# Submission time Handle Problem Language Result Execution time Memory
1104587 2024-10-24T05:58:29 Z TrinhKhanhDung Drzava (COCI15_drzava) C++14
160 / 160
736 ms 56196 KB
#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 time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 1 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 2 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 10 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1652 KB Output is correct
2 Correct 7 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 10 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 15 ms 2536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 10 ms 2364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 7 ms 1916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 118 ms 7232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 733 ms 56196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 736 ms 55248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 445 ms 31196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 553 ms 36980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 607 ms 46876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1616 KB Output is correct
2 Correct 253 ms 10636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 297 ms 18936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 340 ms 25980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 332 ms 26440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 346 ms 17096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 247 ms 13744 KB Output is correct