Manhattan distance - MarisaOJ: Marisa Online Judge

Manhattan distance

Time limit: 1000 ms
Memory limit: 256 MB
Given an 2D array $A$ having $n$ rows and $n$ columns and each cell $(i, j)$ has a value. For each cell $(i, j)$, calculate the sum of all cells having distance less or equal to $k$ to it. The distance between cell $(a, b)$ and cell $(c, d)$ is calculated as following: $$|a-c|+|b-d|$$ ### Input - The first line contains 2 integers $n, k$. - Next $n$ lines, each lines contains $n$ integers $A_{i, j}$. ### Output - Print $n$ lines, each line contains $n$ integers, the integer on row $i$ and column $j$ is the answer of $A_{i, j}$. ### Constraints - $1 \le n, k \le 1000$. - $1 \le A_{i, j} \le 1000$. ### Example Input: ``` 3 1 1 0 2 0 0 1 1 0 0 ``` Output: ``` 1 3 3 2 1 3 1 1 1 ```