{"id":930,"date":"2014-08-07T23:03:02","date_gmt":"2014-08-07T15:03:02","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=930"},"modified":"2014-08-07T23:03:56","modified_gmt":"2014-08-07T15:03:56","slug":"%ef%bc%88ing%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/%ef%bc%88ing%ef%bc%89\/","title":{"rendered":"&#8230;\uff08ing\uff09"},"content":{"rendered":"<p><!--more--><\/p>\n<p>http:\/\/vjudge.net\/contest\/view.action?cid=31226#overview<br \/>\nSPOJ LCS Longest Common Substring<\/p>\n<p>SPOJ LCS2\tLongest Common Substring II<br \/>\nhttp:\/\/vjudge.net\/problem\/viewProblem.action?id=28017<\/p>\n<pre class=\"brush: cpp; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(2e5) + 9, Z = 26;\r\n\r\nnamespace SAM{\r\n\r\n    int trans&#x5B;N]&#x5B;Z],par&#x5B;N],len&#x5B;N],tail,tot;\r\n    char buf&#x5B;N];\r\n\r\n    int new_node(){\r\n        RST(trans&#x5B;tot]);\r\n        return tot++;\r\n    }\r\n    int new_node(int u){\r\n        CPY(trans&#x5B;tot],trans&#x5B;u]),par&#x5B;tot]=par&#x5B;u];\r\n        return tot++;\r\n    }\r\n#define v trans&#x5B;u]&#x5B;c]\r\n#define p par&#x5B;u]\r\n#define pp par&#x5B;uu]\r\n\r\n    int Ext(int c){\r\n\r\n        int u = tail, uu = new_node(); len&#x5B;uu] = len&#x5B;u] + 1;\r\n        while (u &amp;&amp; !v) v = uu, u = p;\r\n        if (!u &amp;&amp; !v) v = uu, pp = 0;\r\n        else{\r\n            if (len&#x5B;v] == len&#x5B;u] + 1) pp = v;\r\n            else{\r\n                int _v = v, vv = new_node(_v); len&#x5B;vv] = len&#x5B;u] + 1;\r\n                par&#x5B;_v] = pp = vv; while (v == _v) v = vv, u = p;\r\n            }\r\n        }\r\n\r\n        return tail = uu;\r\n    }\r\n\r\n#define c (*cur - 'a')\r\n#define lenn C\r\n\r\n    void Init(){\r\n        tail = tot = 0; new_node(), RS(buf); REP_S(cur, buf) Ext(c);\r\n    }\r\n\r\n    int Spell(){\r\n        static int C&#x5B;N], Q&#x5B;N]; \/\/RST(C);\r\n        REP(i, tot) ++C&#x5B;len&#x5B;i]];\r\n        REP_1(i, len&#x5B;tail]) C&#x5B;i] += C&#x5B;i-1];\r\n        REP(i, tot) Q&#x5B;--C&#x5B;len&#x5B;i]]] = i;\r\n\r\n        while (~scanf(&quot;%s&quot;, buf)){\r\n            fill(lenn, lenn+tot, 0); int u = 0, l = 0; REP_S(cur, buf){\r\n                while (u &amp;&amp; !v) l = len&#x5B;u = p];\r\n                if (u = v) checkMax(lenn&#x5B;u], ++l);\r\n            }\r\n            DWN(i, tot, 1){\r\n                int u = Q&#x5B;i]; checkMax(lenn&#x5B;p], lenn&#x5B;u]);\r\n                checkMin(len&#x5B;u], lenn&#x5B;u]);\r\n            }\r\n        }\r\n        int res = 0; FOR(u, 1, tot) checkMax(res, len&#x5B;u]);\r\n        return res;\r\n    }\r\n\r\n} using namespace SAM;\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    Init(), OT(Spell());\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[],"class_list":["post-930","post","type-post","status-publish","format-standard","hentry","category-34"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-f0","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=930"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/930\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}