Automatic Sprayer 2
Time limit2sMemory limit1024 MB
Given the matrix E where E[i][j] is the total Manhattan-distance-weighted spray from all cells, reconstruct any nonnegative integer matrix A that produces it.
- Level
Hard8 of 10
- Topics
- Math, Implementation, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
A farm is divided into unit squares with rows and columns. Let denote the unit square in the -th row and the -th column (, ).
The distance between two squares and is the Manhattan distance .
The farm has automatic sprayers that spray fertilizer solution or herbicide so the owner can produce grain efficiently.
Each sprayer lies entirely in a unit square. The sprayer in sprays liters of solution onto every unit square. is a nonnegative integer.
For the sprayer in to spray solution onto , the energy required is exactly . For each square , let be the sum of energies needed for all sprayers to spray the square .
Given the matrix , write a program that outputs any matrix that corresponds to . is given so that such a matrix of nonnegative integers whose sum is at most exists.
Input
The first line contains a single positive integer ().
The next lines each contain integers. The -th () integer in the -th () line is ().
The input is given so that a matrix consisting of only nonnegative integers whose sum is at most exists and can produce .
Output
Output lines, each containing integers. The -th () integer in the -th () line is .