QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#2700. 繁忙的港口

统计

有两台龙门吊在长度为 $n$ 的同一轨道上运行。轨道上有一些固定的整数位置,编号从 $1$ 到 $n$,龙门吊必须在这些位置执行装卸作业。起初,第一台龙门吊位于轨道最左侧的位置 $1$,而第二台龙门吊位于轨道最右侧的位置 $n$。在每个时间步中,龙门吊可以移动到相邻的整数位置,或者停留在当前位置(并可能执行装卸作业)。为了防止两台龙门吊相撞,第一台龙门吊必须始终严格位于第二台龙门吊的左侧。对于两台龙门吊,你都会得到一个任务列表,其中包含它们必须执行装卸作业的轨道位置。两台龙门吊都必须按给定顺序执行其分配的任务。两台龙门吊完成任务所需的最短时间是多少?保证第一台龙门吊永远不需要在位置 $n$ 进行作业,而第二台龙门吊永远不需要在位置 $1$ 进行作业。对于两台龙门吊,任务列表中的第一个和最后一个装卸作业都是它们的初始位置。

Gantry cranes by wasi1370 on Pixabay

输入格式

输入包含: 一行包含整数 $n, a$ 和 $b$,其中: $n$ ($2 \le n \le 2\,000$) 是轨道的长度; $a$ ($2 \le a \le 50$) 是第一台龙门吊任务列表中的操作次数; $b$ ($2 \le b \le 50$) 是第二台龙门吊任务列表中的操作次数。 一行包含 $a$ 个整数 $k_1, \dots, k_a$ ($1 \le k_i \le n - 1$ 对于所有 $i$),即第一台龙门吊的任务。 一行包含 $b$ 个整数 $\ell_1, \dots, \ell_b$ ($2 \le \ell_i \le n$ 对于所有 $i$),即第二台龙门吊的任务。

两台龙门吊的第一个和最后一个任务都在其初始位置,即 $k_1 = k_a = 1$ 且 $\ell_1 = \ell_b = n$。

输出格式

输出两台龙门吊完成其分配任务所需的最短时间步数。

样例

输入格式 1

3 2 4
1 1
3 3 2 3

输出格式 1

6

说明

在第一个样例测试中,轨道长度为 3,第一台龙门吊有 2 个任务,第二台龙门吊有 4 个任务。两台龙门吊完成任务至少需要 6 个时间步。

时间 第一台龙门吊 第二台龙门吊
1 在 1 处作业 在 3 处作业
2 在 1 处作业 在 3 处作业
3 在 1 处空闲 从 3 移至 2
4 在 1 处空闲 在 2 处作业
5 在 1 处空闲 从 2 移至 3
6 在 1 处空闲 在 3 处作业

输入格式 2

4 4 4
1 2 3 1
4 3 3 4

输出格式 2

9

说明

在第二个样例测试中,轨道长度为 4,两台龙门吊各有 4 个任务。两台龙门吊完成任务至少需要 9 个时间步。

时间 第一台龙门吊 第二台龙门吊
1 在 1 处作业 在 4 处作业
2 从 1 移至 2 从 4 移至 3
3 在 2 处作业 在 3 处作业
4 从 2 移至 3 从 3 移至 4
5 在 3 处作业 在 4 处空闲
6 从 3 移至 2 从 4 移至 3
7 从 2 移至 1 在 3 处作业
8 在 1 处作业 从 3 移至 4
9 在 1 处空闲 在 4 处作业

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.