Density Map
Time limit3sMemory limit128 MB
For each cell of an n by n binary grid, sum the entries within Chebyshev distance r, using a 2D sliding-window or prefix-sum over the square neighborhood.
- Level
Medium4 of 10
- Topics
- Prefix sum, Matrix, Sliding window
- Solved
- No attempts yet
Problem
You are given integers and with , together with an table whose entries belong to . The columns and rows of the table are numbered from to , and the value in column , row is denoted .
The distance between two positions and is defined as .
Compute the table , where equals the sum of all entries such that the distance between and is at most .
Write a program that reads the integers and and the table from standard input, computes the table , and writes it to standard output.
Input
The first line contains two integers and , separated by a single space, with . Each of the next lines describes the table and contains integers from separated by single spaces. The -th number on the -st line equals .
Output
Print exactly lines. On the -th line, print the values in order, separated by single spaces.