SnowflakeOA #20
Closest Random Points (Also for Core/Database Engineering)
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & MathIn-place Arrays
Find the minimum squared Euclidean distance between distinct point entries; coinciding entries have distance 0. The original problem mentions uniform random generation, but correctness must not depend on randomness. The 100,000 points are kept rather than reduced to 2000.
Input
The first line contains n, followed by n lines of x y. Original range: 2≤n≤1000 or n=100000; 0≤x,y≤10⁹−1. Computations and comparisons use exact 64-bit integers; floating-point squared values must not be used.
Output
Output the single integer required by the problem.
Example 1
Input:
3
0 0
1 1
2 4
Output:
2
Example 2
Input:
2
7 7
7 7
Output:
0
Example 3
Input:
2
0 0
999999999 999999999
Output:
1999999996000000002
Example notes
The answers to the three public examples are, in order: 2; 0; 1999999996000000002. All examples have been verified by independent small-scale enumeration or state search.
Editorial
Loading solution…