#P10127. 「Daily OI Round 3」Tower
「Daily OI Round 3」Tower
Background
Define the A-distance between and as . All distances mentioned below refer to the A-distance.
For example, the A-distance between and is .
For example, the A-distance between and is .
Problem Description
The territory of Country A can be seen as an matrix, where the cell in row and column has coordinates .
The land can be mountainous, represented by #, or flat, represented by ..
Country A has built an energy tower on every flat cell. The energy range of an energy tower is a square. If satisfies that all places whose A-distance to this energy tower is not greater than are within the territory of Country A, and those places are flat land, then is called the base energy of this energy tower.
The overall energy of an energy tower is the maximum possible value of its base energy .
In particular, if there is no energy tower at a place, then the overall energy there is . Otherwise, the overall energy there equals the overall energy of the energy tower.
Let the overall energy at row and column be .
Let the total energy sum of a country be $\xi=\sum\limits^n_{i=1}\sum\limits_{j=1}^mE_{i,j}^2$.
You need to compute the total energy sum of the country.
Of course, due to special reasons (such as the effect of cosmic rays), a flat cell may suddenly turn into a mountain. The local energy tower will be destroyed, and this will also affect the overall energy of nearby energy towers.
As an advisor of Country A, the king wants you to prepare a plan: for each non-mountain cell, check what the total energy sum of the country will be after that cell becomes a mountain.
Input Format
The first line contains two integers .
Then follows an matrix. The cell in row and column is # or ., describing the terrain of Country A.
Output Format
Output a total of lines.
The first line contains an integer , the initial total energy sum of Country A.
Then output an matrix: the integer in row and column represents the total energy sum after becomes a mountain. In particular, if is originally a mountain, output .
3 4
....
...#
....
14
10 10 10 13
10 10 10 -1
10 10 10 13
5 6
...#..
#.....
......
......
...#..
39
38 38 38 -1 38 38
-1 35 32 29 32 35
35 32 29 29 32 35
35 32 29 29 32 35
35 35 35 -1 38 38
7 7
....#..
.#.....
.......
.......
.#...##
..#####
.......
51
50 50 50 50 -1 50 50
50 -1 47 44 41 44 47
50 50 44 41 38 44 47
50 50 44 41 38 44 47
50 -1 47 47 47 -1 -1
50 50 -1 -1 -1 -1 -1
50 50 50 50 50 50 50
Hint
[Sample Explanation #1]
Here are examples:
At the beginning, of this country is as follows:
1 1 1 1
1 2 1 0
1 1 1 1
After becomes a mountain, is as follows:
0 1 1 1
1 1 1 0
1 1 1 1
After becomes a mountain, is as follows:
1 1 1 1
1 2 1 0
1 1 1 0
[Constraints]
For all data: .
Translated by ChatGPT 5