Put a code ...
---------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 200009;Const int cn = +;struct Node {Node *fa, *CH[CN];int len, Min, Max;void Upd () {min = min (min, Max);}} POOL[MAXN], *pt, *root, *last;void Upd (node* &t, int &v) {T->max = Max (T->max, v);}node* newNode (int v) {pt->fa = NULL;Pt->len = v;memset (pt->ch, 0, sizeof pt->ch);return pt++;}void Sam_init () {pt = pool;root = last = NewNode (0);}void Extend (int c) {Node *p = last, *NP = NewNode (P->len + 1);For (; p &&!p->ch[c]; p = p->fa)P->ch[c] = NP;if (!p)np->fa = root;else {node* q = p->ch[c];if (p->len + 1 = = Q->len)NP->FA = q;else {node* NQ = NewNode (P->len + 1);memcpy (nq->ch, q->ch, sizeof q->ch);NQ->FA = q->fa;Q->fa = Np->fa = NQ;For (; p && p->ch[c] = = q; p = p->fa)P->ch[c] = NQ;}}Last = NP;} Char S[MAXN];void Sam_build () {scanf ("%s", s);for (int i = 0, n = strlen (s); i < n; i++)Extend (S[i]-' a ');}bool Work () {if (scanf ("%s", s) = =-1)return false;For (node* t = root; t! = pt; t++)T->max = 0;int n = strlen (s);node* t = root;for (int i = 0, lth = 0; i < n; i++) {int c = s[i]-' a ';if (T->ch[c])upd (t = t->ch[c], ++lth);else {for (; t &&!t->ch[c]; t = t->fa);if (!t)t = root, lth = 0;Elselth = T->len + 1, upd (t = t->ch[c], lth);}}For (node* o = pt;--o! = pool;)upd (O->FA, O->max);For (node* o = pt;--o;) {o->upd ();if (o = = Pool) break;}return true;} int main () {sam_init ();sam_build ();For (node* t = root; t! = pt; t++)t->min = t->len;while (work ());int ans = 0;For (node* t = root; t! = pt; t++)ans = max (ans, t->min);printf ("%d\n", ans);return 0;}
---------------------------------------------------------------------
spoj1812 longest Common Substring II (suffix automaton)