{"id":474,"date":"2018-01-04T18:25:42","date_gmt":"2018-01-04T10:25:42","guid":{"rendered":"http:\/\/kylelv.com\/?p=474"},"modified":"2018-01-16T20:52:30","modified_gmt":"2018-01-16T12:52:30","slug":"bzoj-2946-poi2000%e5%85%ac%e5%85%b1%e4%b8%b2-%e5%90%8e%e7%bc%80%e8%87%aa%e5%8a%a8%e6%9c%ba","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=474","title":{"rendered":"bzoj 2946: [Poi2000]\u516c\u5171\u4e32  &#8212; \u540e\u7f00\u81ea\u52a8\u673a"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdef1bef957\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdef1bef957\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#2946_Poi2000%E5%85%AC%E5%85%B1%E4%B8%B2\" title=\"2946: [Poi2000]\u516c\u5171\u4e32\">2946: [Poi2000]\u516c\u5171\u4e32<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=474\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"2946_Poi2000%E5%85%AC%E5%85%B1%E4%B8%B2\"><\/span>2946: [Poi2000]\u516c\u5171\u4e32<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a0<\/span>3 Sec\u00a0\u00a0<span class=\"green\">Memory Limit:\u00a0<\/span>128 MB<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div><\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7ed9\u51fa\u51e0\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u7684\u5355\u8bcd\uff0c\u6c42\u5b83\u4eec\u6700\u957f\u7684\u516c\u5171\u5b50\u4e32\u7684\u957f\u5ea6\u3002<\/div>\n<div>\u4efb\u52a1\uff1a<\/div>\n<div>l\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8bfb\u5165\u5355\u8bcd<\/div>\n<div>l\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8ba1\u7b97\u6700\u957f\u516c\u5171\u5b50\u4e32\u7684\u957f\u5ea6<\/div>\n<div>l\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8f93\u51fa\u7ed3\u679c<\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div><\/div>\n<div>\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\u662f\u6574\u6570\u00a0n\uff0c1&lt;=n&lt;=5\uff0c\u8868\u793a\u5355\u8bcd\u7684\u6570\u91cf\u3002\u63a5\u4e0b\u6765n\u884c\u6bcf\u884c\u4e00\u4e2a\u5355\u8bcd\uff0c\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\uff0c\u5355\u8bcd\u7684\u957f\u5ea6\u81f3\u5c11\u4e3a1\uff0c\u6700\u5927\u4e3a2000\u3002<\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u4ec5\u4e00\u884c\uff0c\u4e00\u4e2a\u6574\u6570\uff0c\u6700\u957f\u516c\u5171\u5b50\u4e32\u7684\u957f\u5ea6\u3002<\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">3<br \/>\nabcb<br \/>\nbca<br \/>\nacbc<br \/>\n<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">\uff12<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u57fa\u672c\u4e0a\u5c31\u662fSAM\u7684\u6a21\u677f\u9898\u5427<\/p>\n<p>\u5173\u4e8eSAM\u00a0\u00a0<a href=\"http:\/\/kylelv.com\/?p=459\" target=\"_blank\" rel=\"noopener\">kylelv.com\/?p=459<\/a><\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;map&gt;\r\n#include&lt;cmath&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;cstring&gt;\r\n#include&lt;iostream&gt;\r\n#include&lt;algorithm&gt;\r\nusing namespace std;\r\n#define inf 1000000007\r\n#define ll long long\r\n#define N 4010\r\nint n,m;\r\nchar s[N];\r\nint fa[N],ch[N][26],l[N],cnt,lst;\r\nvoid ins(int x)\r\n{\r\n\tint p,q,np,nq;\r\n\tp=lst;lst=np=++cnt;l[np]=l[p]+1;\r\n\twhile(!ch[p][x]&amp;&amp;p) ch[p][x]=np,p=fa[p];\r\n\tif(!p){fa[np]=1;return;}\r\n\tq=ch[p][x];\r\n\tif(l[q]==l[p]+1){fa[np]=q;return;}\r\n\tnq=++cnt;l[nq]=l[p]+1;\r\n\tmemcpy(ch[nq],ch[q],sizeof(ch[q]));\r\n\tfa[nq]=fa[q];\r\n\tfa[q]=fa[np]=nq;\r\n\twhile(ch[p][x]==q&amp;&amp;p) ch[p][x]=nq,p=fa[p];\r\n}\r\nint q[N],v[N],ans[N],mx[N];\r\nvoid pre()\r\n{\r\n\tfor(int i=1;i&lt;=cnt;i++) v[l[i]]++;\r\n\tfor(int i=1;i&lt;=n;i++) v[i]+=v[i-1];\r\n\tfor(int i=cnt;i;i--) q[v[l[i]]--]=i;\r\n\tfor(int i=1;i&lt;=cnt;i++) ans[i]=l[i];\r\n}\r\nvoid sol()\r\n{\r\n\tscanf(\"%s\",s+1);\r\n\tn=strlen(s+1);\r\n\tmemset(mx,0,sizeof(mx));\r\n\tint p,now=1,len=0,x;\r\n\tfor(int i=1;i&lt;=n;i++)\r\n\t{\r\n\t\tx=s[i]-'a';\r\n\t\twhile(!ch[now][x]&amp;&amp;now) now=fa[now];\r\n\t\tif(!now) now=1,len=0;\r\n\t\telse len=min(len,l[now])+1,now=ch[now][x];\r\n\t\tmx[now]=max(mx[now],len);\r\n\t}\r\n\tfor(int i=cnt;i;i--) mx[fa[q[i]]]=max(mx[fa[q[i]]],mx[q[i]]);\r\n\tfor(int i=1;i&lt;=cnt;i++) ans[i]=min(ans[i],mx[i]);\r\n}\r\nint Ans; \r\nint main()\r\n{\r\n\tscanf(\"%d\",&amp;m);\r\n\tscanf(\"%s\",s+1);\r\n\tlst=cnt=1;\r\n\tn=strlen(s+1);\r\n\tfor(int i=1;i&lt;=n;i++) ins(s[i]-'a');\r\n\tpre();\r\n\tfor(int i=2;i&lt;=m;i++) sol();\r\n\tfor(int i=1;i&lt;=cnt;i++) Ans=max(Ans,ans[i]);\r\n\tprintf(\"%d\\n\",Ans);\r\n\treturn 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2946: [Poi2000]\u516c\u5171\u4e32 Time Limit:\u00a03 Sec\u00a0\u00a0Memory Limit:\u00a0128 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[49],"class_list":["post-474","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-49"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":3,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"predecessor-version":[{"id":477,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions\/477"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}