Submission details
Task:Closest points
Sender:aalto26jw_004
Submission time:2026-11-11 17:23:42 +0200
Language:Rust (2021)
Status:COMPILE ERROR

Compiler report

error[E0658]: use of unstable library feature 'isqrt'
  --> input/code.rs:32:22
   |
32 |         let h = best.isqrt();
   |                      ^^^^^
   |
   = note: see issue #116226 <https://github.com/rust-lang/rust/issues/116226> for more information

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.

Code

#![allow(unused)]

use std::collections::*;
use std::io;

fn take_int() -> usize {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    return input.trim().parse::<usize>().unwrap();
}

fn take_tuple() -> (i64, i64) {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut it = input.trim().split_whitespace().map(|x| x.parse::<i64>().unwrap());
    (it.next().unwrap(), it.next().unwrap())
}

fn closest_pair(pts: &[(i64, i64)]) -> i64 {
    let mut p: Vec<(i64, i64)> = pts.to_vec();
    p.sort_unstable();
    let mut best = i64::MAX;
    let mut active: BTreeSet<(i64, i64)> = BTreeSet::new(); // stored as (y, x)
    let mut left = 0;
    for i in 0..p.len() {
        let (x, y) = p[i];
        while left < i && (x - p[left].0) * (x - p[left].0) >= best {
            active.remove(&(p[left].1, p[left].0));
            left += 1;
        }

        let h = best.isqrt();
        for &(qy, qx) in active.range((y - h, i64::MIN)..=(y + h, i64::MAX)) {
            let d = (x - qx) * (x - qx) + (y - qy) * (y - qy);
            if d < best {
                best = d;
            }
        }
        active.insert((y, x));
    }
    best
}


fn main() {
    let mut n = take_int();
    let mut pts: Vec<(i64, i64)> = Vec::with_capacity(n);

    for _ in 0..n {
        pts.push(take_tuple());
    }

    let res = closest_pair(&pts);
    println!("{res}");
}