CF1517D Explorer Space
Description
You are wandering in the explorer space of the 2050 Conference.
The explorer space can be viewed as an undirected weighted grid graph with size $ n\times m $ . The set of vertices is $ \{(i, j)|1\le i\le n, 1\le j\le m\} $ . Two vertices $ (i_1,j_1) $ and $ (i_2, j_2) $ are connected by an edge if and only if $ |i_1-i_2|+|j_1-j_2|=1 $ .
At each step, you can walk to any vertex connected by an edge with your current vertex. On each edge, there are some number of exhibits. Since you already know all the exhibits, whenever you go through an edge containing $ x $ exhibits, your boredness increases by $ x $ .
For each starting vertex $ (i, j) $ , please answer the following question: What is the minimum possible boredness if you walk from $ (i, j) $ and go back to it after exactly $ k $ steps?
You can use any edge for multiple times but the boredness on those edges are also counted for multiple times. At each step, you cannot stay on your current vertex. You also cannot change direction while going through an edge. Before going back to your starting vertex $ (i, j) $ after $ k $ steps, you can visit $ (i, j) $ (or not) freely.
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first example, the answer is always $ 10 $ no matter how you walk.
In the second example, $ answer_{21} = 10 $ , the path is $ (2,1) \to (1,1) \to (1,2) \to (2,2) \to (2,1) $ , the boredness is $ 4 + 1 + 2 + 3 = 10 $ .