#abc210d. D - National Railway

D - National Railway

Score : 400400 points

问题描述

王国高桥可以表示为一个具有 HH 行和 WW 列的网格,令 (i,j)(i, j) 表示从北边数第 ii 行、从西边数第 jj 列的方格。

最近,王国公民对修建铁路的需求日益增多,现在国王高桥不得不着手修建。
铁路建设将分为以下两个阶段:

  • 首先,在 两个不同的 方格上各建一个车站。在 (i,j)(i, j) 方格上建造一个车站需要花费 Ai,jA_{i,j} 日元。
  • 然后,修建一条连接这两个车站的铁路轨道。当两个车站分别位于 (i,j)(i, j)(i,j)(i', j') 方格时,修建铁路轨道的成本为 C×(ii+jj)C \times (|i-i'| + |j-j'|) 日元。(其中,x|x| 表示 xx 的绝对值。)

高桥国王优先考虑的是尽可能减少建设成本,而不是提高市民出行便利性。
请输出铁路建设的最小可能总成本。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

The Kingdom of Takahashi can be represented as a grid with HH rows and WW columns. Let (i,j)(i, j) denote the square at the ii-th row from the north and jj-th column from the west.

Recently, there have been more and more requests from the kingdom's citizens to build a railway, and now the king, Takahashi, has no choice but to build one.
The construction of the railway will have the following two phases.

  • First, choose two different squares and build a station on each of them. It costs Ai,jA_{i,j} yen to build a station on the square (i,j)(i, j).
  • Then, build a railway track connecting these two stations. This costs C×(ii+jj)C \times (|i-i'| + |j-j'|) yen when the two stations are on the squares (i,j)(i, j) and (i,j)(i', j'). (x|x| denotes the absolute value of xx.)

Takahashi's priority is to spend as little as possible on this construction, rather than to improve convenience for the citizens.
Print the minimum possible total cost of the construction of the railway.

Constraints

  • 2H,W10002 \leq H, W \leq 1000
  • 1C1091 \leq C \leq 10^9
  • 1Aij1091 \leq A_{ij} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW CC

A1,1A_{1,1} A1,2A_{1,2} \cdots A1,WA_{1,W}

\vdots

AH,1A_{H,1} AH,2A_{H,2} \cdots AH,WA_{H,W}

Output

Print the minimum possible total cost of the construction of the railway.

Sample Input 1

3 4 2
1 7 7 9
9 6 3 7
7 8 6 4

Sample Output 1

10

If we build stations on the squares (1,1)(1, 1) and (2,3)(2, 3), it will cost 1+3=41 + 3 = 4 yen to build the stations and 2×(12+13)=62 \times (|1-2| + |1-3|) = 6 yen to build the track, for a total of 4+6=104+6 = 10 yen. This is the minimum possible total cost of the construction.

Sample Input 2

3 3 1000000000
1000000 1000000 1
1000000 1000000 1000000
1 1000000 1000000

Sample Output 2

1001000001

update @ 2024/3/10 09:24:48