E - Test
Crawling in process...
Crawling failed
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 25E
Description
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring s1, the second enters an infinite loop if the input data contains the substring s2, and the third requires too much memory if the input data contains the substring s3. Bob wants these solutions to fail single test. What is the minimal length of test, which couldn't be passed by all three Bob's solutions?
Input
There are exactly 3 lines in the input data. The i-th line contains string si. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105.
Output
Output one number — what is minimal length of the string, containing s1, s2 and s3
Sample Input
Input
ab bc cd
Output
4
Input
abacaba abaaba x
Output
11
思路:枚举6种排列方式,求出它这些字符串的最大重合数,总的减去最大重合数就是答案。
如三个串是a,b,c;
abc,acb,bac,bca,cab,cba 六种排列。找出最大重合。而这最大重合只能是末尾,所以用个KMP匹配两个串,返回主串结束时,模式串匹配的位置就是最大匹配数。
不过要注意一点,但中间串是前串的子串时,应该用前串与后串匹配。如abc排列,b是a的子串则a与匹配,否则,b与c匹配。