Problem:
Closest Pair

For given n points in metric space, find the distance of the closest points.

Input

n
x0 y0
x1 y1
:
xn-1 yn-1

The first integer n is the number of points.

In the following n lines, the coordinate of the i-th point is given by two real numbers xi and yi. Each value is a real number with at most 6 digits after the decimal point.

Output

Print the distance in a line. The output values should be in a decimal fraction with an error less than 0.000001.

Constraints

2 ≤ n ≤ 100,000

-100 ≤ x, y ≤ 100

Sample Input 1

2
0.0 0.0
1.0 0.0

Sample Output 1

1.000000

Sample Input 2

3
0.0 0.0
2.0 0.0
1.0 1.0

Sample Output 2

1.41421356237

Solution in Kotlin (judge verdict: Wrong Answer)

import java.math.BigDecimal
import java.util.*

class Point(val x: Double, val y: Double) {
    operator fun minus(other: Point): Double {
        return Math.sqrt(Math.pow(this.x-other.x, 2.0)+Math.pow(this.y-other.y, 2.0))
    }
    operator fun get(i: Int): Double = if (i == 0) x else y
}
fun solve(a: Array<Point>): Double {
    if (a.size <= 3) {
        var dist = 1000000000000.0
        for (i in 0 until a.size-1) {
            for (j in i+1 until a.size) dist = Math.min(dist, a[i]-a[j])
        }
        return dist
    }

    val mid = a.size/2
    val xSetLen = a.map { it -> it.x }.toHashSet().size
    val (axis1, axis2) = if (xSetLen >= mid) Pair(0, 1) else Pair(1, 0)
    a.sortBy { it[axis1] }
    var delta = Math.min(
            solve(a.sliceArray(0 until mid)),
            solve(a.sliceArray(mid until a.size))
    )
    val median = a[mid][axis1]
    val mid_a = a.filter { it[axis1] in median-delta..median+delta }.sortedBy { it[axis2] }
    for (i in 0 until mid_a.size-1) {
        val ub = mid_a[i][axis2]
        for (j in i+1..mid_a.size) {
            if (mid_a[i][axis2] >= ub) break
            delta = Math.min(delta, mid_a[i]-mid_a[j])
        }
    }

    return delta
}
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val a = Array(N, { Point(sc.nextDouble(), sc.nextDouble()) })
    val ans = solve(a)
    println(BigDecimal.valueOf(ans).toPlainString())
}