QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100

#12184. 大与

Statistics

你需要构建一个布尔电路,以计算一组源信号的逻辑与(AND)。问题在于你只有一组相同的 AND 门,每个门有两个布尔输入(即 True 或 False),并且仅当两个输入均为 True 时,输出才为 True。

回顾你的数字电路课程,你记得可以将这些 AND 门连接起来(将某些门的输出连接到其他门的输入),从而构建一个电路。该电路为每个需要考虑的源信号提供一个输入,并产生一个输出,该输出仅当所有源信号均为 True 时才为 True。更准确地说,你应该构建一个满足以下属性的电路:

  • 电路中恰好有 $N - 1$ 个 AND 门,其中 $N$ 是源信号的数量。
  • 每个源信号都将连接到恰好一个 AND 门的输入。
  • 电路中 AND 门的每个输入都连接到恰好一个信号,该信号要么是源信号之一,要么是另一个 AND 门的输出信号。
  • 信号中不存在“环路”:一个 AND 门的输出信号永远不会到达其自身的输入线。

最后,电路的输出将连接到一个 LED,用于指示该信号是 True 还是 False。因此,当且仅当所有源信号均为 True 时,LED 才会亮起。

你希望以一种方式完成此操作,使得如果其中一个输入信号发生变化,输出信号发生变化的最坏情况延迟最小。你知道以下信息:

  • 如果源信号 $i$ 的值发生变化,则该变化到达你的电路需要恰好 $n_i$ 纳秒。
  • 对于任何 AND 门,在输入信号发生变化后,输出信号发生变化需要恰好 $D$ 纳秒(如果新的输入会导致输出发生变化)。
  • 当 LED 接收到的信号发生变化时,LED 发生变化需要恰好 $L$ 纳秒。
  • 由于电路的组件放置得非常靠近,信号从一个 AND 门的输出传播到电路中另一个组件所需的时间可以忽略不计,视为 0 纳秒。

请帮助设计一个电路,以最小化从其中一个源信号发生变化到 LED 发生变化(如果新的输入确实会导致 LED 发生变化)之间的最大时间。

输入格式

输入的第一行包含三个整数 $N$ ($2 \le N \le 4 \cdot 10^5$)、$D$ 和 $L$ ($1 \le D, L \le 10^9$),其中 $N$ 是源信号的数量,$D$ 和 $L$ 如题目描述所述。第二行包含 $N$ 个整数 $n_1, n_2, \dots, n_N$ ($1 \le n_i \le 10^9$),其中 $n_i$ 表示源信号 $i$ 的变化到达你的电路所需的纳秒数。

输出格式

输出最小的时间 $T$,使得可以构建一个电路,确保如果其中一个源信号发生变化(且该变化会导致 LED 发生变化),LED 发生变化所需的时间最多为 $T$ 纳秒。

图 C.1:每个样例输入的最佳电路示意图。左侧的数字表示源信号的索引。

样例

样例输入 1

3 3 5
3 8 1

样例输出 1

16

样例输入 2

5 5 10
5 8 3 3 3

样例输出 2

28

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.