#P9089. 「SvR-2」Work

    ID: 9315 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>字符串二分洛谷原创后缀自动机 SAMO2优化哈希 hashing洛谷月赛

「SvR-2」Work

Problem Description

Given nn strings consisting of lowercase letters, define the value of the ii-th string as the number of its meaningful substrings (if there are multiple essentially identical substrings, they are also counted multiple times). A substring of the ii-th string is meaningful if and only if it can be split into several strings, where each part is a suffix of any of the nn strings.

Here is an example with n=4n=4:

int
printf
scanf
ntnt
  • For the string printf, the substring intf is meaningful, because it can be represented as int and f, which are suffixes of int and scanf, respectively. However, rint is not.

  • For the string ntnt, the substring ntnt is also meaningful, because it can be represented as nt and nt (both are the same suffix of int), or it can be represented as ntnt, which is a suffix of ntnt.

Now, Little Z wants to know the sum of the values of these nn strings.

Input Format

The first line contains an integer nn.

Then follow nn lines, each containing a string.

Output Format

Output one integer in one line, representing the sum of the values.

4
int
printf
scanf
ntnt
23
4
ireallywanttobemissjiaransdog
butmissjiaransaidthatshelikedcatsandicried
iknowwhyicrywheniamneitheradognoracatbecauseimactuallyamouse
ineverexpectedmissjiarantolikeherselfiunderstandthatallpeopleliketounderstandthecutedogorcatthatyuyuusestomakemoneyandnoonelikesthemousewithwetandwetdiseases
391

Hint

Constraints

This problem uses bundled testdata and O2 optimization.

Let sis_i denote the length of the ii-th string.

Subtask Constraints / Special Properties Score
11 n3n\le 3, si10\sum\limits \lvert s_i\rvert\le10 5pts5 \operatorname{pts}
22 n=26n=26, each string consists of only one character
33 n=1n=1 15pts15 \operatorname{pts}
44 si2000\sum\limits \lvert s_i \rvert \le 2000
55 si2×105\sum\limits \lvert s_i \rvert \le 2\times10^5 30pts30 \operatorname{pts}
66 si106\sum\limits \lvert s_i \rvert \le 10^6

For 100%100\% of the testdata, 1n5×1051\le n \le 5\times10^5, and nsi106n\le \sum\limits \lvert s_i \rvert \le 10^6.

Translated by ChatGPT 5