记录编号 161030 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [POI 2000] 最长公共子串 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 0.035 s
提交时间 2015-04-30 18:11:29 内存使用 6.98 MiB
显示代码纯文本
/*****************************************************************************/
/******************************Designed By Asm.Def****************************/
/*****************************************************************************/
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <ctime>
#define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) )
#define FREAD
#define FREADLENTH 5000000
#ifdef FREAD
char *fread_ptr = (char*)malloc(FREADLENTH);
#define getc() (*(fread_ptr++))
#else
#define getc() getchar()
#endif
using namespace std;
template<class T>inline void getd(T &x){
	int ch = getc();bool neg = false;
	while(!isdigit(ch) && ch != '-')ch = getc();
	if(ch == '-')neg = true, ch = getc();
	x = ch - '0';
	while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
	if(neg)x = -x;
}
/*******************************************************************************/
const int maxn = 10006;
struct SAM{
	SAM *link, *son[26];
	int len, st;
}Node[maxn<<1], *iter = Node + 1, *last;
#define newnode() (iter++)

inline void insert(int ch){
	SAM *cur = newnode(), *it = last, *clone, *t;
	cur->len = last->len + 1;
	while(it && !it->son[ch])it->son[ch] = cur, it = it->link;
	if(!it)cur->link = Node;
	else {
		t = it->son[ch];
		if(it->len + 1 == t->len)cur->link = t;
		else{
			clone = newnode();*clone = *t;clone->len = it->len + 1;
			t->link = cur->link = clone;
			do{
				it->son[ch] = clone;
				it = it->link;
			}while(it && it->son[ch] == t);
		}
	}
	last = cur;
}
int n;
inline void init(){
	getd(n);
	int i;
	SAM *it;
	char str[2003], *c = str;
	for(i = 0;i < n;++i){
		last = Node;c = str;
		while(!isalpha(*c = getc()));while(isalpha(*c))*(++c) = getc();
		*c = 0;
		for(c = str;*c;++c)insert(*c - 'a');
		it = last;while(it)it->st |= 1 << i, it = it->link;
	}
}

inline bool cmp(int a, int b){return Node[a].len < Node[b].len;}

int Arr[maxn<<1];
int calc(){
	int i = 0, N = (1 << n) - 1, j;
	SAM *it;
	for(it = Node;it < iter;++it, ++i)Arr[i] = i;
	sort(Arr, Arr + i, cmp);
	while(i--){
		it = Node + Arr[i];
		for(j = 0;j < 26;++j)if(it->son[j])it->st |= it->son[j]->st;
		if(it->st == N)return it->len;
	}
	return 0;
}

int main(){

#ifdef DEBUG
	freopen("test.txt", "r", stdin);
#else
	SetFile(pow);
#endif
#ifdef FREAD
	fread(fread_ptr, 1, FREADLENTH, stdin);
#endif
	init();
	printf("%d\n", calc());

#ifdef DEBUG
	printf("\n%.3lf sec\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}