﻿ Codeforces25E

## 题目链接

https://codeforces.com/contest/25/problem/E

## AC_Code

```#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
string s[N] ;
int nex[N];
void get_nex(string s , int *nex)
{
int i = 0 , j = -1 , len = s.size();
nex[i] = j;
while(i < len)
{
while(j != -1 && s[i] != s[j]) j = nex[j];
nex[++ i] = ++ j ;
}
}
int KMP(string s , string t)
{
get_nex(t , nex) ;
int i = 0 , j = 0 , lens = s.size() , lent = t.size();
while(i < lens)
{
while(j != -1 && s[i] != t[j]) j = nex[j];
i ++ , j ++ ;
if(j == lent) return lent;
}
return j;
}
int solve(string a , string b , string c)
{
int pos = KMP(a , b);
a += b.substr(pos , b.size() - pos);
pos = KMP(a , c);
return a.size() + c.size() - pos;
}
signed main()
{
ios::sync_with_stdio(false);
cin >> s[1] >> s[2] >> s[3];
sort(s + 1 , s + 1 + 3);
int ans = s[1].size() + s[2].size() + s[3].size();
do{
ans = min(ans , solve(s[1] , s[2] , s[3]));
}while(next_permutation(s + 1 , s + 1 + 3));
cout << ans << '
' ;
return 0;
}```