CF2045G X Aura
题目描述
Mount ICPC 可以被表示为一个网格,共有 $R$ 行(编号从 $1$ 到 $R$)和 $C$ 列(编号从 $1$ 到 $C$)。位于第 $r$ 行和第 $c$ 列的单元格被表示为 $(r, c)$,其高度为 $H_{r, c}$。两个单元格是相邻的,如果它们共享一条边。正式来说,$(r, c)$ 相邻于 $(r-1, c)$、$(r+1, c)$、$(r, c-1)$ 和 $(r, c+1)$,如果这些单元格存在。
你只能在相邻的单元格之间移动,每次移动都会产生一个惩罚。具有一个奇数正整数 $X$ 的气场,从高度为 $h_1$ 的单元格移动到高度为 $h_2$ 的单元格会产生 $(h_1 - h_2)^X$ 的惩罚。注意,惩罚可以是负数。
你想回答 $Q$ 个独立的场景。在每个场景中,你从起始单元格 $(R_s, C_s)$ 开始,想要移动到目标单元格 $(R_f, C_f)$,以最小的总惩罚。有些场景可能会使总惩罚变得任意小,这样的场景被称为无效的。找到从起始单元格到目标单元格的最小总惩罚,或者确定场景是否无效。
输入格式
无
输出格式
无
说明/提示
Explanation for the sample input/output #1
For the first scenario, one of the solutions is to move as follows: $ (1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4) $ . The total penalty of this solution is $ (3 - 4)^1 + (4 - 3)^1 + (3 - 6)^1 + (6 - 8)^1 + (8 - 1)^1 = 2 $ .
Explanation for the sample input/output #2
For the first scenario, the cycle $ (1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (1, 2) \rightarrow (1, 1) $ has a penalty of $ (1 - 2)^5 + (2 - 0)^5 + (0 - 9)^5 + (9 - 1)^5 = -26250 $ . You can keep repeating this cycle to make your total penalty arbitrarily small. Similarly, for the second scenario, you can move to $ (1, 1) $ first, then repeat the same cycle.