QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#10208. 全能的……花环

الإحصائيات

Rikka 终于在月亮塔顶睡着了。她梦见了 LCR 那串她一直非常感兴趣的独特花环。花环由 $n$ 朵两种类型的花组成:洋紫荆(Bauhinia Blakeana)和山樱花(Cerasus Yedoensis)。为方便起见,我们用“B”和“C”来简称它们。这 $n$ 朵花排成一个环,即每朵花都有一个 $[0, n)$ 范围内的整数索引,使得花 $i$ 和 $((i + 1) \pmod n)$ 相邻。

Rikka 选择了两个神奇的正整数 $m, k$。现在她想把花环分成 $m$ 个较短的子花环,使得每个子花环的长度都是 $k$ 的倍数,每个子花环中的花保持它们在原花环中的相对顺序,并且每个子花环中都存在两朵相邻的“B”。你需要回答是否存在这样的合法划分,如果存在,输出其中任意一种。

形式化地,令 $t[i]$ ($i = 0, 1, \dots, n - 1$) 为索引为 $i$ 的花的类型(“B”或“C”)。一个包含 $c$ 朵花的子花环可以描述为一个递增序列 $A = \{A_0, A_1, \dots, A_{c-1}\}$ ($A_i < A_{i+1}, i = 0, 1, \dots, c - 2$),它表示这些花在原花环中的索引。我们也将 $A$ 看作序列 $A$ 中所有元素的集合。Rikka 想要找到 $m$ 个序列 $S_1, S_2, \dots, S_m$,使得 $\cup_{i=1}^m S_i = \{0, 1, \dots, n - 1\}$,$\sum_{i=1}^m |S_i| = n$,并且对于 $i = 1, 2, \dots, m$,$|S_i|$ 是 $k$ 的倍数,且存在 $x, y$ ($x, y \in \mathbb{Z}$) 满足以下条件:

  • $0 \le x, y < |S_i|$
  • $x \neq y$
  • $x \equiv (y + 1) \pmod{|S_i|}$
  • $t[S_{ix}] = t[S_{iy}] = \text{“B”}$

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。接下来是 $T$ 个测试用例。 每个测试用例的输入格式如下: 第一行包含三个整数 $n, m, k$ ($1 \le n, m, k \le 10^6$),分别表示花环的长度、子花环的数量以及子花环长度的因子。 第二行包含一个长度为 $n$ 的字符串 $t$,其中第 $i$ 个字符为“B”或“C”,表示 $t[i]$ ($i = 0, 1, \dots, n - 1$),即花 $i$ 的类型。 保证所有测试用例中 $n$ 的总和不超过 $10^6$。

输出格式

按顺序回答每个测试用例。对于每个测试用例,输出格式如下: 第一行包含字符串“Yes”或“No”(不含引号)。如果存在合法的划分,输出“Yes”,否则输出“No”。 如果答案为“Yes”,则在接下来的 $m$ 行中输出子花环。每行的第一个整数是该子花环的长度 $|S_i|$。随后的 $|S_i|$ 个整数是该子花环中各朵花在原花环中的索引,按升序排列。

样例

输入 1

4
6 2 2
BBCCBB
6 2 3
BBCCBB
4 4 1
BBBB
12 2 3
BBCCBCCBBCCC

输出 1

Yes
2 0 1
4 2 3 4 5
Yes
3 0 1 2
3 3 4 5
No
Yes
6 0 1 2 3 5 6
6 4 7 8 9 10 11

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.