Submit | All submissions | Best solutions | Back to list |
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
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 |
hide comments
2015-12-07 09:33:49 Harsh Gupta
Time limit is very strict. Getting TLE for O(nlogn) solution. |
|
2015-05-19 05:21:17 Pagan Min
any hints for the problem...cant get a start |
|
2014-03-17 19:33:45 aristofanis
For those who don't like this sample test case (like @c0d3junki3 below), here is an other one: Input: ------------- 7 81 48 78 50 47 13 70 43 61 28 73 56 58 21 Output: ------------- 5 5 19 15 10 11 10 Last edit: 2014-03-17 19:35:01 |
|
2013-08-01 12:22:00 Dragan MarkoviƦ
Worst sample case ever. Not to mention to allowing latest gcc... |
|
2012-11-25 09:49:08 Nic Roets
@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 |
|
2012-09-30 23:01:20 karan173
hey please increase time limit for java as there are no currently accepted solutions |
|
2009-04-14 17:10:31 Khanh Quynh
If N=1 what's the result? |