{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n 字符串匹配是计算机科学中常见的一类问题。一个字符串匹配问题如下: \n \u003cbr\u003e \n \u003cbr\u003e给定一个字符串s[0…len−1],请对于每个i\u003e0,计算s[i…len−1]和s[0…len−1]的最长公共前缀的长度。 \n \u003cbr\u003e \n \u003cbr\u003e我相信每个人都可以用暴力来做。\n \u003cbr\u003e暴力方法的伪代码如下: \n \u003cbr\u003e \n \u003cbr\u003e \n \u003ccenter\u003e \n \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/7dc667a229be739b423147cd5977924a?v\u003d1607071153\"\u003e \n \u003c/center\u003e \n \u003cbr\u003e \n \u003cbr\u003e我们想知道,对于任何给定的字符串,如果使用上述算法,调用的比较操作的数量是多少。在我们尝试运行此算法之前,请告诉我们答案。 \n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\nThe first line contains an integer T, denoting the number of test cases. \n\u003cbr\u003eEach test case contains one string in a line consisting of printable ASCII characters except space. \n\u003cbr\u003e \n\u003cbr\u003e* 1\u003c T \u003c 30\n\u003cbr\u003e \n\u003cbr\u003e* string length \u003c 10^6 for every string\n\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test, print an integer in one line indicating the number of compare operations invoked if we run the algorithm in the statement against the input string."}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e3\n_Happy_New_Year_\nywwyww\nzjczzzjczjczzzjc\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e17\n7\n32\u003c/pre\u003e"}}]}