{"id":610,"date":"2017-05-02T23:05:00","date_gmt":"2017-05-02T15:05:00","guid":{"rendered":"http:\/\/kylelv.com\/?p=610"},"modified":"2020-03-04T14:23:11","modified_gmt":"2020-03-04T06:23:11","slug":"bzoj-2342-shoi2011%e5%8f%8c%e5%80%8d%e5%9b%9e%e6%96%87-manacher","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=610","title":{"rendered":"bzoj 2342: [Shoi2011]\u53cc\u500d\u56de\u6587 &#8212; manacher"},"content":{"rendered":"\n<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-69fdef88acab4\" 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-69fdef88acab4\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=610\/#2342_Shoi2011%E5%8F%8C%E5%80%8D%E5%9B%9E%E6%96%87\" title=\"2342: [Shoi2011]\u53cc\u500d\u56de\u6587\">2342: [Shoi2011]\u53cc\u500d\u56de\u6587<\/a><\/li><\/ul><\/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=610\/#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=610\/#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=610\/#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=610\/#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=610\/#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=610\/#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=610\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"2342_Shoi2011%E5%8F%8C%E5%80%8D%E5%9B%9E%E6%96%87\"><\/span>2342: [Shoi2011]\u53cc\u500d\u56de\u6587<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"has-text-align-center\">Time Limit:&nbsp;10 Sec&nbsp;&nbsp;Memory Limit:&nbsp;128 MB<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"578\" height=\"484\" src=\"http:\/\/kylelv.com\/wp-content\/uploads\/2020\/03\/2342_0.gif\" alt=\"\" class=\"wp-image-611\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8f93\u5165\u5206\u4e3a\u4e24\u884c\uff0c\u7b2c\u4e00\u884c\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff0c\u7b2c\u4e8c\u884c\u6709\u4e2a\u8fde\u7eed\u7684\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u7b26\uff0c\u8868\u793a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8f93\u51fa\u6587\u4ef6\u53ea\u6709\u4e00\u884c\uff0c\u5373\uff1a\u8f93\u5165\u6570\u636e\u4e2d\u5b57\u7b26\u4e32\u7684\u6700\u957f\u53cc\u500d\u56de\u6587\u5b50\u4e32\u7684\u957f\u5ea6\uff0c\u5982\u679c\u53cc\u500d\u56de\u6587\u5b50\u4e32\u4e0d\u5b58\u5728\uff0c\u5219\u8f93\u51fa0\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>16<br>ggabaabaabaaball<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>12<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>N&lt;=500000<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u9996\u5148\u6211\u4eecmanacher\u5904\u7406\u51fa\u6bcf\u4e2a\u4f4d\u7f6e\u7684\u6700\u957f\u56de\u6587\u4e32<\/p>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u679a\u4e3e\u5bf9\u79f0\u8f74\uff0c\u6839\u636e\u9898\u610f\u53ef\u4ee5\u77e5\u9053\u5bf9\u79f0\u8f74\u4e00\u5b9a\u5728\u4e24\u4e2a\u5b57\u7b26\u4e2d\u95f4\uff08\u5373&#8221;#&#8221;\u5904\uff09<\/p>\n\n\n\n<p>\u5e76\u5bf9\u4e8e\u6bcf\u8fb9\u5206\u522b\u679a\u4e3e\u5bf9\u79f0\u8f74\uff0c\u5224\u65ad\u662f\u5426\u5408\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;map>\n#include&lt;cmath>\n#include&lt;queue>\n#include&lt;cstdio>\n#include&lt;cstring>\n#include&lt;iostream>\n#include&lt;algorithm>\nusing namespace std;\n#define ll long long\n#define N 1000100\nint n,mx,md,p&#91;N],ans;\nchar c&#91;N],s&#91;N];\nint main()\n{\n    scanf(\"%d%s\",&amp;n,s+1);c&#91;0]='*';\n    for(int i=1;i&lt;=n;i++){c&#91;(i&lt;&lt;1)-1]='#';c&#91;i&lt;&lt;1]=s&#91;i];}\n    n&lt;&lt;=1;c&#91;++n]='#';c&#91;++n]='!';\n    for(int i=1;i&lt;n;i++)\n    {\n        p&#91;i]=mx>i?min(p&#91;(md&lt;&lt;1)-i],mx-i):1;\n        while(c&#91;i-p&#91;i]]==c&#91;i+p&#91;i]]) p&#91;i]++;\n        if(p&#91;i]+i>mx) mx=p&#91;i]+i,md=i;\n    }\n    for(int i=1;i&lt;n;i+=2)\n    {\n        int j=p&#91;i]>>1;if(j&amp;1) j--;\n        for(;j&amp;&amp;j*2>ans;j-=2)\n            if(p&#91;i-j]>j&amp;&amp;p&#91;i+j]>j) ans=max(ans,j&lt;&lt;1);\n    }\n    printf(\"%d\\n\",ans);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2342: [Shoi2011]\u53cc\u500d\u56de\u6587 Time Limit:&nbsp;10 Sec&nbsp;&#038;nbsp [&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":[53],"class_list":["post-610","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-manacher"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/610","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=610"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/610\/revisions"}],"predecessor-version":[{"id":612,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/610\/revisions\/612"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}