|
||||||||||
Route StatisticsTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 224 Accepted Submission(s): 133 Problem Description JRY is so rich that he creates an $m$ demensional space and $n$ sight spots inside. Because of special technical problem, all the coordinates are integers between $[0,2]$. The roads in this space are all parallel to the axis, so the distance between two sight spots is their Manhattan distance. More specifically, if the coordinate of one sight spot is $(x_1,x_2,\ldots,x_m)$, and that of another sight spot is $(y_1,y_2,\ldots,y_m)$, then their distance is $\sum_{i=1}^{m}|x_i-y_i|$. JRY wants to establish some bus routes between two sight spots, so he needs to do some research first. For you, the problem is to find the total number of pairs $(x,y)$ for each $k$, that the distance between $(x,y)$ is $k$. Please be aware: 1. $(x,x)$ does not count; 2. $(x,y)$ and $(y, x)$ are identical, so that it is only one pair; 3. different sight spots may have same coordinates. Input The first line of the input is a single integer $T\ (T = 11)$, indicating the number of testcases. For each testcase, the first line contains two integers $n$ and $m$. Each of the following $n$ lines contains one string of length $m$, which consists three types of characters $0, 1, 2$, and the $j$-th character of the $i$-th string means the $j$-th coordinate of the $i$-th spot. It is guaranteed that the $m$ of the $i$-th testcase is $i$, and for all testcases $\sum n \le 300000$. Output For each testcase, print $2m+1$ lines. The single number in the $i$-th line of the output indicates the number of pairs of sight spots with distance $i-1$ Sample Input
Sample Output
Author XJZX Source | ||||||||||
|