QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 2048 MB Total points: 100

#10316. A Very Long Hike

統計

你正在计划一次在葡萄牙北部的佩内达-热雷什国家公园(Peneda-Gerês National Park)的徒步旅行。该公园以其两座最高峰命名:佩内达(1340 米)和热雷什(1545 米)。

对于本题,公园被建模为一个无限平面,其中每个位置 $(x, y)$($x, y$ 为整数)都有一个特定的海拔高度。海拔高度由一个 $n \times n$ 的矩阵 $h$ 定义,该矩阵在整个平面上周期性重复。具体而言,对于任意整数 $a, b$ 以及 $0 \le x, y < n$,位置 $(x + an, y + bn)$ 的海拔高度为 $h[x][y]$。

当你处于位置 $(x, y)$ 时,你可以移动到四个相邻位置中的任意一个:$(x, y + 1)$、$(x + 1, y)$、$(x, y - 1)$ 或 $(x - 1, y)$。在两个相邻位置之间移动所需的时间为 $1 + |alt_1 - alt_2|$,其中 $alt_1$ 和 $alt_2$ 分别是当前位置和目标位置的海拔高度。

初始时,你的位置是 $(0, 0)$。计算你在 $10^{20}$ 秒内可以到达的不同位置的数量。如果你的答案的相对误差小于 $10^{-6}$,则视为正确。

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 20$),表示描述海拔高度的矩阵的大小。

接下来的 $n$ 行,每行包含 $n$ 个整数。这些行中第 $(i + 1)$ 行的第 $(j + 1)$ 个数字是 $h[i][j]$ ($0 \le h[i][j] \le 1545$),表示位置 $(i, j)$ 的海拔高度。

输出格式

输出你在 $10^{20}$ 秒内可以到达的不同位置的数量。如果你的答案的相对误差小于 $10^{-6}$,则视为正确。

样例

输入 1

2
3 3
3 3

输出 1

2e+40

说明 1

佩内达-热雷什国家公园的每个位置海拔高度均为 3。因此,在两个相邻位置之间移动所需的时间始终等于 1 秒。

在这种情况下,可以证明一个位置 $(x, y)$ 在 $10^{20}$ 秒内可达,当且仅当 $|x| + |y| \le 10^{20}$。可以计算出存在 20 000 000 000 000 000 000 200 000 000 000 000 000 001 个可达位置,该数字近似为 $2 \cdot 10^{40}$,相对误差小于 $10^{-6}$。样例输出显示 $2 \cdot 10^{40}$ 为正确答案,但精确的可达位置数量也是正确答案。

输入 2

3
0 0 0
0 1545 0
0 0 0

输出 2

2e+40

说明 2

佩内达-热雷什国家公园中所有满足 $x - 1$ 和 $y - 1$ 能被 3 整除的位置 $(x, y)$ 海拔高度为 1545,而所有其他位置的海拔高度为 0。例如,在 $(4, 10)$ 和 $(4, 9)$ 之间移动所需的时间为 1546,而在 $(3, 2)$ 和 $(4, 2)$ 之间移动所需的时间为 1。

在 2 秒内可达的位置是所有满足 $|x|+|y| \le 2$ 且不等于 $(1, 1)$(位于峰顶)的位置。可以计算出在 $10^{20}$ 秒内存在 19 999 999 999 999 999 931 533 333 333 333 333 863 441 个可达位置,该数字近似为 $2 \cdot 10^{40}$,相对误差小于 $10^{-6}$。样例输出显示 $2 \cdot 10^{40}$ 为正确答案,但精确的可达位置数量也是正确答案。

输入 3

4
0 1 2 3
5 6 7 4
10 11 8 9
15 12 13 14

输出 3

1.524886878e+39

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.