QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 512 MB مجموع النقاط: 100 الصعوبة: [عرض]

#1832. 螃蟹大炮

الإحصائيات

Crab 先生是一位著名的工程师。他最近发明了一种威力巨大的新武器,叫做“回文大炮”(The Palindromic Cannon)。要用这门大炮发射,必须装填一个由无限字母表中的字母组成的字符串,其长度为 $\ell$。

我们将字符串的“回文前缀集”(Palindromic Prefix Set, PPS)定义为所有满足“长度为 $i$ 的前缀是回文串”的数字 $i$ ($1 \le i \le \ell$) 的集合。例如,字符串 “abacaba” 的 PPS 为 $\{1, 3, 7\}$,字符串 “aaaa” 的 PPS 为 $\{1, 2, 3, 4\}$。PPS 的大小被称为字符串 $s$ 的“强度”(force)。

Crab 先生想测试他的新武器。于是,他写下了一个字符串 $s$,准备装入大炮。但他突然感到非常疲倦,便睡着了。当他醒来时,发现字符串不见了,因为敌方间谍 Crabbarc 先生和 Barc 先生闯入了他的房子,并对字符串进行了一些操作。

首先,Crabbarc 先生拿走了字符串,并将它的 PPS 以随机顺序写成了一个序列。然后,Barc 先生闯入 Crab 先生的房子,可能擦除了 Crabbarc 先生写下的一些数字。

Crab 先生需要你的帮助。你需要恢复他的字符串 $s$ 并告诉他该字符串的强度。由于恢复字符串的方法可能有很多种,你需要找到恢复后的字符串的最小可能强度。

输入格式

输入包含多个测试用例。每个测试用例的格式如下:

每个测试用例的第一行包含两个整数 $n$ 和 $\ell$ ($1 \le n \le 3 \cdot 10^5$, $1 \le \ell \le 10^{18}$),分别表示 Crab 先生在 Crabbarc 和 Barc 先生离开后找到的序列长度,以及初始字符串的长度。

每个测试用例的第二行包含 $n$ 个整数 $a_i$ ($1 \le a_i \le \ell$),即序列中的数字。保证所有数字互不相同。

在最后一个测试用例之后,有一行包含 “0 0”。你的程序在读取该行后应正常终止。

保证所有测试用例的 $n$ 之和不超过 $3 \cdot 10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数:恢复后的字符串的最小可能强度。

样例

输入 1

3 7
1 3 7
4 12
7 1 3 9
3 16
16 1 8
0 0

输出 1

3
5
3

说明

在第一个测试用例中,最小强度字符串的一种可能是 “abacaba”。其 PPS 为 $\{1, 3, 7\}$,因此其强度为 3。

在第二个测试用例中,字符串可能是 “cbcbcbcbcrab”。其 PPS 为 $\{1, 3, 5, 7, 9\}$,因此其强度为 5。可以证明,无法恢复出强度更小的字符串。

在第三个测试用例中,考虑字符串 “crabbarccrabbarc”。其 PPS 为 $\{1, 8, 16\}$,因此其强度为 3。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download
#546Editorial Open集训队作业 解题报告 by 武林Qingyu2026-01-02 22:07:37 Download

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.