Wow, you made it ... Konjac Konjac that year noi this problem ... But took 0 points oh ~(nonsense so much, you weak blame me Ah!) )
We first KMP the next array and the CNT array, where CNT represents the number of pattern strings that he can match before.
Then, in a similar KMP, record next next array, next = next + length limit.
So... Ans =π (Cnt[next[i]] + 1) (1≤i≤len)
1 /**************************************************************2 problem:36703 User:rausen4 language:c++5 result:accepted6 time:664 Ms7 memory:13500 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <cstring> A - using namespacestd; -typedefLong Longll; the Const intLen =1000005; - Constll mod =1000000007; - - CharSt[len]; + intLen, Next[len], Next[len], Cnt[len]; - ll ans; + AInlinevoidWork_next () { at intI, t; - for(i =1; I <= Len; ++i) { -t = next[i-1]; - while(t! =-1&& st[i]! = st[t +1]) -t =Next[t]; -Next[i] = t +1, cnt[i] = cnt[t +1] +1; in } - } to +InlinevoidWork_next () { - intI, t; the for(i =1; I <= Len; ++i) { *t = next[i-1]; $ if(T *2+2> i) t =Next[t];Panax Notoginseng while(t! =-1&& st[i]! = st[t +1]) -t =Next[t]; theNext[i] = t +1; + } A } the + intMain () { - intT, I; $scanf"%d\n", &T); $ while(t--) { -Gets (St +1), Len = strlen (st +1); -next[0] = next[0] = -1; the Work_next (); - Work_next ();Wuyi for(i = ans =1; I <= Len; ++i) the(Ans *= (cnt[next[i]) +1)) %=MoD; -printf"%lld\n", ans); Wu } -}
View Code
BZOJ3670 [Noi2014] Zoo