# Count points on same distance from set of points

Let's consider finite grid of points with size of $N$ by $M$ and set of $x$ points ($x$ is small number, up to 10, $N$ and $M$ are big numbers, up to 30000 )). Each of the $x$ points is described with 2 values $(x_i, y_i)$. We want to count the size of set $y$ such that $y$ includes all the points in the grid that are on equal distance from all of the $x$ points.

By distance I mean Manhattan distance.

• What's your question? What have you tried? What algorithms have you already considered? Are you able to come up with any algorithm at all, regardless of running time? What's wrong with the obvious algorithm: try each grid point, calculate its distance to each of the $x$ points, and see if it belongs in the output? What's wrong with the next-most-obvious algorithm, of looping over the distance $d$ and for each $d$, enumerating all points that are at distance $d$ from all of the $x$ points? – D.W. Mar 12 '18 at 21:17
• For the first obvious algorithm, the wrong is that it is very slow $O(NM)$ if $N = M = 30000$. The second algorithm has the same complexity, if i'm getting it correct. – someone12321 Mar 13 '18 at 6:32
• Please define "very slow". Have you actually measured it? How do you plan to evaluate answers? What quantitative metric do you plan to use? Doing $10 \times 30000^2$ distance computations sounds like something that can be done in fractions of a second. No, the second algorithm might be faster. My other questions still stand. I suggest you spend some more time trying out the obvious approaches, see if they meet your needs, and if you rejected them, use that to figure out what exactly your requirements are, and edit the question to provide additional context. – D.W. Mar 13 '18 at 16:22
• On standard computer being able to process $10^8$ computations per second, $10\cdot 30000^2$ is going to take 90 seconds. I need algorithm that will finish it under 1 second. I tried many of those searches but they all work in the same complexity, so we need to find some different search. – someone12321 Mar 14 '18 at 6:13