QOJ.ac

QOJ

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

#8172. 404 Chotto Found

الإحصائيات

给定 $N$ 个字符串 $S_1, S_2, \dots, S_N$。求满足以下条件的非空字符串 $T$ 的数量:

  • 在 $N$ 个字符串 $S_1, S_2, \dots, S_N$ 中,恰好有一个字符串包含 $T$ 作为(连续)子串。

输入格式

输入通过标准输入给出,格式如下:

$N$ $S_1$ $S_2$ $\vdots$ $S_N$

  • $1 \le N \le 10^5$
  • $1 \le |S_i| \le 10^6$ ($1 \le i \le N$)
  • $\sum_{i=1}^N |S_i| \le 10^6$
  • $S_i$ ($1 \le i \le N$) 由小写英文字母组成。

输出格式

输出答案。

样例

样例输入 1

2
abc
ca

样例输出 1

5

样例输入 2

2
aab
aab

样例输出 2

0

样例输入 3

1
aba

样例输出 3

5

样例输入 4

3
tokyoinstituteoftechnology
tokyomedicalanddentaluniversity
instituteofsciencetokyo

样例输出 4

905

说明

样例 1

考虑 $T = \text{'a'}$ 的情况,由于 $S_1 = \text{'abc'}$ 和 $S_2 = \text{'ca'}$ 都包含 $\text{'a'}$ 作为子串,因此不满足条件。 对于 $T = \text{'ab'}$,只有 $S_1 = \text{'abc'}$ 包含 $\text{'ab'}$ 作为子串,因此满足条件。 对于 $T = \text{'d'}$,由于 $S_1 = \text{'abc'}$ 和 $S_2 = \text{'ca'}$ 都不包含 $\text{'d'}$ 作为子串,因此不满足条件。 满足条件的字符串为 $T = \text{'b'}, \text{'ab'}, \text{'bc'}, \text{'ca'}, \text{'abc'}$,共 5 个。

样例 2

考虑 $T = \text{'ab'}$ 的情况,由于 $S_1 = \text{'aab'}$ 和 $S_2 = \text{'aab'}$ 都包含 $\text{'ab'}$ 作为子串,因此不满足条件。 没有满足条件的字符串。

样例 3

满足条件的字符串为 $T = \text{'a'}, \text{'b'}, \text{'ab'}, \text{'ba'}, \text{'aba'}$,共 5 个。

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.