Submission #1084794

# Submission time Handle Problem Language Result Execution time Memory
1084794 2024-09-07T02:36:44 Z TrinhKhanhDung Drzava (COCI15_drzava) C++14
0 / 160
1 ms 600 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
#define INF (ll)1e9
#define MOD (ll)(998244353)

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());}

const int MAXN = 5e4 + 10, MAXK = 35;

int N, K;

struct city{
    ll x, y, c;
    city(ll _x = 0, ll _y = 0, ll _c = 0){
        x = _x;
        y = _y;
        c = _c;
    }
};
vector<city> cities;
vector<city> edges;

ll sqr(ll n){return n * n;}

ll dist(pair<ll, ll> a, pair<ll, ll> b){
    return sqr(a.fi - b.fi) + sqr(a.se - b.se);
}

set<int> mrge(set<int> &a, set<int> &b){
    set<int> ans;
    for(int i: a) for(int j: b){
        ans.insert((i + j) % K);
    }
    for(int i: a) ans.insert(i);
    for(int i: b) ans.insert(i);
    return ans;
}

struct DSU{
    vector<int> par, Sz;
    vector<set<int>> sets;

    DSU(int n = 0){
        par.resize(n + 3);
        Sz.resize(n + 3);
        sets.resize(n + 3);
        for(int i=0; i<=n; i++){
            par[i] = i;
            Sz[i] = 1;
        }
    }

    int root(int u){
        return u == par[u] ? u : par[u] = root(par[u]);
    }

    bool join(int a, int b){
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(Sz[a] < Sz[b]) swap(a, b);
        Sz[a] += Sz[b];
        par[b] = a;
        sets[a] = mrge(sets[a], sets[b]);
        return true;
    }
};

void solve(){
    cin >> N >> K;
    for(int i=1; i<=N; i++){
        int x, y, c;
        cin >> x >> y >> c;
        cities.push_back(city(x, y, c));
    }
    sort(ALL(cities), [&](city a, city b){if(a.x == b.x) return a.y < b.y; return a.x < b.x;});
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            edges.push_back(city(i, j, dist({cities[i].x, cities[i].y}, {cities[j].x, cities[j].y})));
        }
    }
    DSU dsu(N);
    for(int i=0; i<N; i++){
        dsu.sets[i].insert(cities[i].c % K);
    }
    for(auto o: edges){
//        cout << o.x << ' ' << o.y << ' ' << o.c << '\n';
        o.x = dsu.root(o.x);
        o.y = dsu.root(o.y);
        if(o.x != o.y){
            for(int i: dsu.sets[o.x]) for(int j: dsu.sets[o.y]){
                if((i + j) % K == 0){
                    cout << fixed << setprecision(3) << sqrtl(o.c) << '\n';
                    return;
                }
            }
           dsu.join(o.x, o.y);
        }
//        for(int i: dsu.sets[o.x]) cout << i << ' ';
//        cout << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("task.inp", "r", stdin);
    // freopen("task.ans", "w", stdout);

    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -