E. Test
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 as substrings.

Sample test(s)
input
ab
bc
cd
output
4
input
abacaba
abaaba
x
output
11

KMP

给你3个子串,求最短的原串。

例如

abc

ab

c

最短原串就是abc

/* ***********************************************
Author :pk29
Created Time :2015/8/23 18:41:02
File Name :4.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; int f[maxn];
void getFail(string p,int *f){
int m=p.size();
f[]=;
f[]=;
for(int i=;i<m;i++){
int j=f[i];
while(j&&p[i]!=p[j])j=f[j];
f[i+]=p[i]==p[j]?j+:;
}
}
int find(string t,string p,int *f){
int n=t.size(),m=p.size();
getFail(p,f);
int j=;
for(int i=;i<n;i++){
while(j&&p[j]!=t[i])j=f[j];
if(p[j]==t[i])j++;
if(j==m)return ;//一开始没考率到主串包含子串,wa成狗
}
return m-j;
} string s[];
int arr[]={,,};
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
while(cin>>s[]>>s[]>>s[]){
if(s[]>s[])swap(s[],s[]);
if(s[]>s[])swap(s[],s[]);
if(s[]>s[])swap(s[],s[]);
//next_permutation()使用前得先排序
int ans=INF;
int num=;
do{
string t="";
t+=s[];
int a=find(t,s[],f);
t+=s[].substr(s[].size()-a,a);
int b=find(t,s[],f);
int x=t.size()+b;
ans=min(ans,x);
}while(next_permutation(s,s+));
cout<<ans<<endl;
}
return ;
}

Codeforces Beta Round #25 (Div. 2 Only)E. Test的更多相关文章

  1. Codeforces Beta Round #25 (Div. 2 Only)

    Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...

  2. codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...

  3. Codeforces Beta Round #25 (Div. 2)--A. IQ test

    IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  4. Codeforces Beta Round #25 (Div. 2 Only) A. IQ test【双标记/求给定数中唯一的奇数或偶数】

    A. IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  5. Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland

    D. Roads not only in Berland time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Beta Round #25 (Div. 2 Only) C. Roads in Berland

    C. Roads in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  8. Codeforces Beta Round #49 (Div. 2)

    Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...

  9. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

随机推荐

  1. 【bzoj1193】[HNOI2006]马步距离

    [HNOI2006]马步距离 Description Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Output 含一个整数,表示从 ...

  2. Count Numbers

    Count Numbers 时间限制: 8 Sec  内存限制: 128 MB 题目描述 Now Alice wants to sum up all integers whose digit sum ...

  3. 洛谷 P2831 愤怒的小鸟

    P2831 愤怒的小鸟 题目描述 Kiana 最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于 (0,0)(0,0) 处,每次 Kiana 可以用它向第一象 ...

  4. htmlcxx取指定字段实例

    #include <string> #include <iostream> #include <sstream> #include <htmlcxx/html ...

  5. 《Java虚拟机原理图解》 1.1、class文件基本组织结构

    作为Java程序猿,我们知道,我们写好的.java 源代码,最后会被Java编译器编译成后缀为.class的文件,该类型的文件是由字节组成的文件,又叫字节码文件.那么,class字节码文件里面到底是有 ...

  6. iOS--基于键值的观察者模式(KVO)

    VO简而言之就是:基于键值的观察者,实际上就是观察者模式. Cocoa Framework已经为我们提供了这一模式,不需要我们自己来实现了.我们只需要按照约定的方式去做就可以了.KVO主要用于用户界面 ...

  7. 经典游戏“大富翁4”存档文件修改器Rich4Editor下载

    下载地址: http://files.cnblogs.com/files/xiandedanteng/Rich4Editor20170614.zip http://files.cnblogs.com/ ...

  8. photoshop 前端常用技巧

    1.将图片转换成 png 格式 并且 使背景透明 (1)用矩形选框工具选取一块区域 (2)右键 选择 ‘变换选区’ 进行微调 F8 查看尺寸 (3)复制图层(ctrl+c) ->新建文件(ctr ...

  9. Android开发的环境搭建及HelloWorld的实现

    安装JDK和配置Java开发环境 http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-4321 ...

  10. python实现的websocket总结 —— wspy

    之前曾有php版的websocket封装包.见Websocket--php实战,近期使用python做一些功能,须要用到对websocket的操作,因此,參照之前的实现,实现了这个python版本号. ...