O(N^2/2) distance matrix computation