GANNHAT - Closest distance
English | Vietnamese |
The manhattan distance between two points A(x1,y1) and B(x2,y2) is defined as following:
D(A,B) = |x1 - x2| + |y1 - y2|
Given N points A1, A2, ..., AN, for each point Ai you need to calculate the minimum D(Ai , Aj) (j ≠ i).
Input
- The first line contains a positive integer N (1 ≤ N ≤ 200000).
- The i-th line of the next N lines contains two integers x and y which are co-ordinates of the i-th point(0 ≤ x, y ≤ 107)
Output
- Print N lines, in which the i-th line contains the minimum distance for the i-th point.
Example
Input: 4 0 0 0 1 1 0 1 1 Output: 1 1 1 1
hide comments
Harsh Gupta:
2015-12-07 09:33:49
Time limit is very strict.
|
|
Pagan Min:
2015-05-19 05:21:17
any hints for the problem...cant get a start |
|
aristofanis:
2014-03-17 19:33:45
For those who don't like this sample test case (like @c0d3junki3 below), here is an other one:
|
|
Dragan MarkoviƦ:
2013-08-01 12:22:00
Worst sample case ever.
|
|
Nic Roets:
2012-11-25 09:49:08
@Khanh There is no test for that (I got AC and my output for N=1 is random.) Last edit: 2012-11-25 09:49:34 |
|
karan173:
2012-09-30 23:01:20
hey please increase time limit for java as there are no currently accepted solutions |
|
Khanh Quynh:
2009-04-14 17:10:31
If N=1 what's the result? |
Added by: | Kaiel |
Date: | 2008-05-02 |
Time limit: | 0.100s-1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CPP JAVA PAS-GPC PAS-FPC |
Resource: | Mr Taek |