QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 512 MB Total points: 100

#888. 环游中国

Statistics

Rikka 是一个富有的女孩。

她想要游览中国美丽的城市。中国的城市位置可以简单地看作一个包含 $n$ 行 $m$ 列的网格。行从北到南编号为 $1$ 到 $n$,列从西到东编号为 $1$ 到 $m$。位于第 $i$ 行第 $j$ 列的城市被称为 $(i, j)$。

全国各地有一些高速公路连接。城市 $(i, j)$ 与城市 $(x, y)$ 之间有直接的高速公路,当且仅当 $|i - x| + |j - y| = 1$。由于新年临近,高速公路现已免费向公众开放。

当 Rikka 从城市 $(i, j)$ 前往 $(x, y)$ 时,她只能通过高速公路旅行。一条旅行路线的费用是她所经过的所有城市的费用之和,包括起点和终点城市。如果路线包含某个城市,她就会去参观景点、购物并消费。如果路线包含城市 $(i, j)$,她将花费 $a_{i,j}$ 元。如果她总共访问城市 $(i, j)$ $k$ 次,她将花费 $k \cdot a_{i,j}$ 元,因为总有足够的购物中心供她消费。

Rikka 是一个异想天开的女孩,她甚至没有设定起点和终点城市。她想知道所有起点和终点城市不同的最廉价路线的费用之和。换句话说,令 $f(i, j, x, y)$ 为从城市 $(i, j)$ 出发并以城市 $(x, y)$ 结束的路线的最小费用。她想知道以下值:

$$\sum_{i=1}^{n} \sum_{x=1}^{n} \sum_{j=1}^{m} \sum_{y=1}^{m} [(i, j) \neq (x, y)] f(i, j, x, y)$$

由于答案可能非常大,你只需要告诉她答案对 $1\,000\,000\,007$(即 $10^9 + 7$)取模后的结果。

输入格式

第一行包含两个整数 $n$ 和 $m$。

接下来的 $n$ 行,每行包含 $m$ 个整数。第 $i$ 行的第 $j$ 个数字是 $a_{i,j}$ 的值。

保证 $n = 3$,$1 \le m \le 1.5 \cdot 10^5$,且 $1 \le a_{i,j} \le 10^9$。

输出格式

输出一行,包含一个整数,即答案对 $1\,000\,000\,007$(即 $10^9 + 7$)取模后的结果。

样例

样例输入 1

3 3
1 1 1
1 100 1
1 1 1

样例输出 1

1808

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.