QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100

#16093. 塔式停车场

Statistiques

停车场行业迎来了一项新的革命:停车塔。其概念非常简单:你将车开进停车塔入口处的电梯,然后电梯和传送带会将车拖到一个空车位上,车辆会一直停放在那里,直到你来取车。当你回来时,电梯和传送带会将你的车送回入口,这样就完成了。

停车塔的布局很简单。有一部中央电梯用于在不同楼层之间运送车辆。每个楼层都有一条巨大的环形传送带,车辆停放在上面。该传送带可以顺时针或逆时针方向移动。当电梯到达某个楼层时,它会成为该传送带的一部分,以便车辆可以通过它。

在一天结束时,停车塔通常停满了车,许多人会来取车。顾客按照先来后到的顺序进行服务:电梯移动到第一辆车所在的楼层,传送带将车移入电梯,电梯再次向下移动(回到第一层的入口),依此类推。我们想知道在最后一位顾客拿到他的车之前需要多长时间。电梯向上或向下移动一层需要 $10$ 秒,传送带向任一方向移动一个车位需要 $5$ 秒。

输入格式

第一行包含一个正整数:测试用例的数量,最多为 $100$。对于每个测试用例:

  • 一行包含两个整数 $h$ 和 $l$($1 \le h \le 50$,$2 \le l \le 50$):表示停车塔的高度和传送带的长度。
  • $h$ 行,每行包含 $l$ 个整数:表示车辆的初始位置。第 $i$ 行的第 $j$ 个数字描述了第 $i$ 层第 $j$ 个位置的状态。如果该位置为空,则该数字为 $-1$;如果该位置被第 $r$ 辆要取走的车辆占用,则该数字为 $r$。正整数构成一个从 $1$ 到车辆总数的连续序列。入口位于第一层,电梯(初始为空)位于第一个位置。停车塔中至少有一辆车。

输出格式

对于每个测试用例:

  • 输出一行,表示最后一位顾客拿到车之前所需的秒数。

样例

输入 1

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

输出 1

25
320

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.