CF1535F.String Distance
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Suppose you are given two strings a and b . You can apply the following operation any number of times: choose any contiguous substring of a or b , and sort the characters in it in non-descending order. Let f(a,b) the minimum number of operations you have to apply in order to make them equal (or f(a,b)=1337 if it is impossible to make a and b equal using these operations).
For example:
- f(ab,ab)=0 ;
- f(ba,ab)=1 (in one operation, we can sort the whole first string);
- f(ebcda,ecdba)=1 (in one operation, we can sort the substring of the second string starting from the 2 -nd character and ending with the 4 -th character);
- f(a,b)=1337 .
You are given n strings s1,s2,…,sk having equal length. Calculate i=1∑nj=i+1∑nf(si,sj) .
输入格式
The first line contains one integer n ( 1≤n≤2⋅105 ) — the number of strings.
Then n lines follow, each line contains one of the strings si , consisting of lowercase Latin letters. ∣s1∣=∣s2∣=…=∣sn∣ , and n⋅∣s1∣≤2⋅105 . All these strings are pairwise distinct.
输出格式
Print one integer: i=1∑nj=i+1∑nf(si,sj) .
输入输出样例
输入#1
4 zzz bac abc acb
输出#1
4015
输入#2
2 a b
输出#2
1337