답안 #1084795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084795 2024-09-07T02:41:27 Z TrinhKhanhDung Drzava (COCI15_drzava) C++14
64 / 160
86 ms 65536 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(make_pair(cities[i].x, cities[i].y), make_pair(cities[j].x, cities[j].y))));
        }
    }
    sort(ALL(edges), [&](city a, city b){
        return a.c < b.c;
    });
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 37 ms 12768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 35 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 15 ms 6628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 35 ms 12768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 47 ms 12844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 13 ms 6612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 67 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 73 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 79 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 74 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 80 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 82 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 76 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 74 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 81 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 86 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 75 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 80 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -