QOJ.ac

QOJ

Límite de tiempo: 4.5 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#10819. 石之海

Estadísticas

在 JoJo 的世界里,有些人能够将内在的精神力量转化为“替身”(Stand)。空条徐伦(Cujoh Jolyne)和她的父亲一样,拥有替身能力。她的替身名为“石之自由”(Stone Free),能够操纵线。不幸的是,她被陷害并被判处 15 年监禁,关押在绿海豚监狱(Green Dolphin Prison)。她需要利用替身能力来帮助自己从“石之海洋”中重获自由。

由于她才刚刚获得替身能力,还需要一些时间来适应。现在有 $n$ 个字符串 $S_1, S_2, \dots, S_n$。她想要通过以下步骤来训练自己的能力:

  1. 设定索引 $i = 1$,并将 $T$ 设为空字符串。
  2. 从 $S_i$ 中均匀随机地选择一个字符,这意味着每个字符被选中的概率为 $\frac{1}{|S_i|}$,其中 $|S_i|$ 是 $S_i$ 的长度。
  3. 将选中的字符追加到 $T$ 的末尾。
  4. 如果 $i < n$,将 $i$ 增加 1 并返回第 2 步。

完成这些步骤后,空条徐伦得到了另一个字符串 $T$。她将 $T$ 的“能量值”定义为满足以下条件的排列 $p_1, p_2, \dots, p_n$ 的数量:$T_{p_1} T_{p_2} \dots T_{p_n}$ 是一个回文串。

回文串定义为从左往右读和从右往左读完全相同的字符串。例如,aa, aba, acca 是回文串,而 ab, cab 则不是。排列 $p_1, p_2, \dots, p_n$ 是一个 $1$ 到 $n$ 的整数各出现恰好一次的序列。

为了评估她力量的强度,空条徐伦想要知道字符串 $T$ 的能量值的期望。

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 30$)。

接下来的 $n$ 行中,第 $i$ 行包含一个仅由小写字母组成的字符串 $S_i$ ($1 \le |S_i| \le 50000$,其中 $|S_i|$ 是 $S_i$ 的长度)。

输出格式

输出一个整数,表示字符串 $T$ 的能量值的期望,对 998244353 取模。形式化地,令 $M = 998244353$。可以证明答案可以表示为不可约分数 $\frac{p}{q}$,其中 $p$ 和 $q$ 是整数且 $q \not\equiv 0 \pmod M$。输出 $p \cdot q^{-1} \pmod M$,其中 $q^{-1}$ 表示 $q$ 在模 $M$ 意义下的乘法逆元。

样例

样例输入 1

2
ab
ac

样例输出 1

499122177

样例输入 2

4
aabcc
abab
bbaa
acac

样例输出 2

399297744

说明

对于第一个样例,字符串 $T$ 可能为 aa, ac, ba, bc,且概率相同,它们的能量值分别为 2, 0, 0, 0。因此能量值的期望为 $\frac{2+0+0+0}{4} = \frac{1}{2}$。

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.