Submission #630145

# Submission time Handle Problem Language Result Execution time Memory
630145 2022-08-15T18:11:22 Z Hacv16 Odašiljači (COCI20_odasiljaci) C++17
70 / 70
288 ms 51524 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << ": " << "[ " << x << " ]\n"

struct Antena{
    int id;
    ld x, y;

    Antena(int i = 0, ld a = 0.0, ld b = 0.0){
        id = i, x = a, y = b;
    }

    ld dist(Antena other){
        ld dx = x - other.x, dy = y - other.y;
        return dx * dx + dy * dy;
    }
};

int n, seen[MAX], cnt;
vector<Antena> v;
vector<int> adj[MAX];

void dfs(int u){
    seen[u] = true, cnt++;

    for(auto v : adj[u]){
        if(!seen[v]) dfs(v);
    }
}

bool check(ld d){
    for(int i = 0; i < n; i++){
        adj[i].clear();
        seen[i] = false;
    }

    cnt = 0;

    for(int i = 0; i < n; i++)
        for(int j = i + 1; j < n; j++)
            if(v[i].dist(v[j]) <= d * d)
                adj[v[i].id].pb(v[j].id), adj[v[j].id].pb(v[i].id);

    dfs(0);

    return (cnt == n);           
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    cin >> n;

    for(int i = 0; i < n; i++){
        ld x, y; cin >> x >> y;
        v.pb(Antena(i, x, y));
    }

    long double l = 0, r = 1e10, ans = -1;

    while(r - l > eps){
        ld m = (r + l) / 2.0;
        if(check(m)) r = m, ans = m;
        else l = m;
    }   

    cout << setprecision(15) << fixed << ans / 2.0 << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47188 KB Output is correct
3 Correct 26 ms 47296 KB Output is correct
4 Correct 27 ms 47324 KB Output is correct
5 Correct 26 ms 47308 KB Output is correct
6 Correct 111 ms 48308 KB Output is correct
7 Correct 111 ms 48356 KB Output is correct
8 Correct 199 ms 50444 KB Output is correct
9 Correct 288 ms 51524 KB Output is correct
10 Correct 262 ms 51400 KB Output is correct