#P6833. [Cnoi2020] 雷雨

[Cnoi2020] 雷雨

Background

Uneasy clouds begin to cover the sky.
Huge buildings creak in the strong wind.
Discordant sounds echo throughout Gensokyo.
— “Touhou Kishinjou ~ Double Dealing Character”.

On a stormy night with thunder and lightning, a bolt of lightning struck the Scarlet Devil Mansion by the Misty Lake and the Bamboo Forest of the Lost.

It seems that something big is about to happen, and Cirno is quietly thinking in her hut.

Problem Description

The vertical cross-section of Gensokyo can be abstracted as an n×mn \times m rectangle.

Each 1×11 \times 1 cell (i,j)(i,j) has a resistance measurement value (a fictional concept) Ri,jR_{i,j}.

The lightning is emitted from O(n,a)\texttt{O}(n,a) on the thundercloud, and hits the Scarlet Devil Mansion A(1,b)\texttt{A}(1,b) and the Bamboo Forest of the Lost B(1,c)\texttt{B}(1,c) on the ground.

Since lightning is a natural creation, it will choose positions so that the total resistance measurement value is minimized. That is, the sum of resistance measurement values over the union of the two paths from O\texttt{O} to A\texttt{A} and B\texttt{B} is minimized.

So, when the resistance measurements at all positions are known, Cirno wants to know the minimum possible sum of resistance measurement values along the lightning’s paths.

Input Format

The first line contains five integers n,m,a,b,cn,m,a,b,c. (0<a,b,cm)(0<a,b,c\le m).

The next nn lines each contain mm integers, representing the resistance measurement Ri,jR_{i,j}. The first row represents the thundercloud, and the last row represents the ground.

Output Format

One line with one integer, representing the answer.

5 5 1 2 4
1 8 1 6 6
1 1 1 2 4
8 3 1 2 2
1 2 1 9 1
1 0 9 1 1
15

Hint

Sample Explanation

As shown in the figure, the yellow lines are the lightning’s paths.

Constraints

For 100%100\% of the testdata, it is guaranteed that: 0<n,m10000<n,m \le 1000, 0Ri,j1090 \le R_{i,j}\le 10^9, 0<a,b,cm0< a,b,c \le m.

Subtasks “This problem uses bundled tests”

  • Subtask 1 (10%10\%): Ri,j{1}R_{i,j}\in\{1\}.
  • Subtask 2 (10%10\%): Ri,j{0,1}R_{i,j}\in\{0,1\}.
  • Subtask 3 (10%10\%): a=b=ca=b=c.
  • Subtask 4 (10%10\%): n,m5n,m \le 5.
  • Subtask 5 (60%60\%): No special constraints.

Translated by ChatGPT 5