#P16287. [蓝桥杯 2026 省 Python A 组] 单词合并

    ID: 18302 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>字符串哈希 hashing2026蓝桥杯省赛STL

[蓝桥杯 2026 省 Python A 组] 单词合并

Problem Description

Xiaolan has nn pairwise distinct words s1,s2,,sns_1, s_2, \dots, s_n in the dictionary. Each word consists only of lowercase letters, and its length does not exceed 2020.

Xiaolan defines an operation: perform exactly one of the following two transformations on a word:

  • Insert one lowercase letter at any position.
  • Delete any one letter from it.

Except for the inserted or deleted position, the relative order of the original letters remains unchanged.

Now, please count how many ordered word pairs (si,sj)(s_i, s_j) (where iji \ne j) satisfy: sis_i can be transformed into sjs_j by performing exactly one operation as defined above.

Input Format

The first line contains a positive integer nn.

The next nn lines each contain a string consisting only of lowercase letters, representing a word.

Output Format

Output one line containing one integer, representing the number of ordered word pairs that satisfy the condition.

5
aab
ab
a
bb
b
8

Hint

Sample Explanation

The 88 ordered word pairs that satisfy the condition are:

  • (aab,ab)(aab, ab): delete the 11st letter aa from aabaab to get abab.
  • (ab,aab)(ab, aab): insert the letter aa at the 11st position of abab to get aabaab.
  • (ab,a)(ab, a): delete the 22nd letter bb from abab to get aa.
  • (a,ab)(a, ab): insert the letter bb at the 22nd position of aa to get abab.
  • (ab,b)(ab, b): delete the 11st letter aa from abab to get bb.
  • (b,ab)(b, ab): insert the letter aa at the 11st position of bb to get abab.
  • (bb,b)(bb, b): delete the 11st letter bb from bbbb to get bb.
  • (b,bb)(b, bb): insert the letter bb at the 11st position of bb to get bbbb.

Constraints

For 30%30\% of the testdata, 1n1001 \leq n \leq 100.

For all testdata, 1n100001 \leq n \leq 10000. It is guaranteed that all words are pairwise distinct.

Translated by ChatGPT 5