QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#10811. 十字路口

الإحصائيات

城市中有 $n$ 行 $m$ 列,共 $n \cdot m$ 个交叉路口。第 $i$ 行第 $j$ 列的交叉路口具有两个属性 $a_{i,j}, b_{i,j}$。我们用一对整数 $(i, j)$ 来表示第 $i$ 行第 $j$ 列的交叉路口。

当行人位于交叉路口 $(i, j)$ 时,对于任意非负整数 $k$:

  • 如果当前时间在 $[k \cdot a_{i,j} + k \cdot b_{i,j}, (k + 1) \cdot a_{i,j} + k \cdot b_{i,j})$ 内,行人可以选择走到交叉路口 $(i - 1, j)$(如果 $i > 1$)或交叉路口 $(i + 1, j)$(如果 $i < n$)。
  • 如果当前时间在 $[(k + 1) \cdot a_{i,j} + k \cdot b_{i,j}, (k + 1) \cdot a_{i,j} + (k + 1) \cdot b_{i,j})$ 内,行人可以选择走到交叉路口 $(i, j - 1)$(如果 $j > 1$)或交叉路口 $(i, j + 1)$(如果 $j < m$)。

你可以选择原地停留。在 $(i, j)$ 和 $(i, j + 1)$ 之间往返需要 $c_{i,j}$ 的时间,在 $(i, j)$ 和 $(i + 1, j)$ 之间往返需要 $w_{i,j}$ 的时间。通过交叉路口不需要时间。

在时刻 $0$,你位于交叉路口 $(x_s, y_s)$,想要前往交叉路口 $(x_t, y_t)$。请问最少需要多少时间?

输入格式

第一行包含六个正整数 $n, m, x_s, y_s, x_t, y_t$ ($2 \le n, m \le 500, 1 \le x_s, x_t \le n, 1 \le y_s, y_t \le m$),含义如题目描述所述。

接下来 $n$ 行,每行包含 $m$ 个正整数。第 $i$ 行的第 $j$ 个数表示交叉路口 $(i, j)$ 的属性 $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$)。

接下来 $n$ 行,每行包含 $m$ 个正整数。第 $i$ 行的第 $j$ 个数表示交叉路口 $(i, j)$ 的属性 $b_{i,j}$ ($1 \le b_{i,j} \le 10^9$)。

接下来 $n$ 行,每行包含 $m - 1$ 个正整数。第 $i$ 行的第 $j$ 个数表示交叉路口 $(i, j)$ 与 $(i, j + 1)$ 之间的道路长度 $c_{i,j}$ ($1 \le c_{i,j} \le 10^9$)。

接下来 $n - 1$ 行,每行包含 $m$ 个正整数。第 $i$ 行的第 $j$ 个数表示交叉路口 $(i, j)$ 与 $(i + 1, j)$ 之间的道路长度 $w_{i,j}$ ($1 \le w_{i,j} \le 10^9$)。

输出格式

输出一行一个整数,表示答案。

样例

输入 1

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

输出 1

33

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.