CF1483F.Exam
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This year a Chunin Selection Exam is held again in Konoha, and taking part in it are n ninjas named s1, s2, ..., sn. All names are distinct. One of the exam stages consists of fights between the participants. This year the rules determining the ninjas for each fight are the following: ninjas i and j fight against each other if the following conditions are held:
- i=j;
- sj is a substring of si;
- there is no k except i and j that sj is a substring of sk, and sk is a substring of si.
A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
Your task is to find out how many fights are going to take place this year.
今年,木叶村再次举行了中忍选拔考试,共有 n 名忍者参加,他们的名字分别为 s1, s2, ..., sn,且所有名字互不相同。考试的一个环节是选手之间的对战。今年每场对战的参赛者由以下规则确定:忍者 i 与忍者 j 进行对战,当且仅当下列条件全部满足:
- i=j;
- sj 是 si 的子串;
- 不存在除 i 和 j 外的某个 k,使得 sj 是 sk 的子串,且 sk 是 si 的子串。
字符串 a 是字符串 b 的子串,当且仅当 a 可通过从 b 的开头删除若干(可能为零或全部)字符、并从 b 的末尾删除若干(可能为零或全部)字符而得到。
你的任务是计算今年总共将进行多少场对战。
输入格式
The first line consists of the only integer n (1≤n≤106) standing for the number of examinees.
The following n lines contain their names. No two names coincide, all names are non-empty and consist of lowercase English letters. The total length of all names doesn't exceed 106.
第一行包含唯一一个整数 n(1≤n≤106),表示考生人数。
接下来的 n 行包含考生姓名。任意两个姓名互不相同,所有姓名均非空,且仅由小写英文字母组成。所有姓名的总长度不超过 106。
输出格式
Print the only integer standing for the number of fights.
输出唯一的一个整数,表示战斗的次数。
输入输出样例
输入#1
5 hidan dan hanabi bi nabi
输出#1
3
输入#2
4 abacaba abaca acaba aca
输出#2
4
说明/提示
In the first example hidan fights against dan, and hanabi fights against nabi, who also fights bi. Ninjas named hanabi and bi don't fight each other since there is the ninja called nabi who breaks the third condition for them.
In the second example the fights are held between abacaba and acaba, abacaba and abaca, acaba and aca, abaca and aca.
在第一个例子中,hidan 与 dan 对战,hanabi 与 nabi 对战,而 nabi 还与 bi 对战。名为 hanabi 和 bi 的忍者彼此之间不进行对战,因为存在一名名为 nabi 的忍者,他破坏了二者之间满足第三条件的要求。
在第二个例子中,对战发生在 abacaba 与 acaba、abacaba 与 abaca、acaba 与 aca、abaca 与 aca 之间。
输入解题思路,AI测评打分。不知道怎么写?