{"id":509,"date":"2017-04-27T15:58:27","date_gmt":"2017-04-27T07:58:27","guid":{"rendered":"http:\/\/kylelv.com\/?p=509"},"modified":"2018-01-18T17:09:08","modified_gmt":"2018-01-18T09:09:08","slug":"bzoj-3940-usaco2015-febcensoring-ac%e8%87%aa%e5%8a%a8%e6%9c%ba","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=509","title":{"rendered":"bzoj 3940: [Usaco2015 Feb]Censoring  &#8212; AC\u81ea\u52a8\u673a"},"content":{"rendered":"<p>&nbsp;<\/p>\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-69fdef754e7e5\" 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-69fdef754e7e5\"  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=509\/#3940_Usaco2015_FebCensoring\" title=\"3940: [Usaco2015 Feb]Censoring\">3940: [Usaco2015 Feb]Censoring<\/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=509\/#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=509\/#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=509\/#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=509\/#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=509\/#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=509\/#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=509\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"3940_Usaco2015_FebCensoring\"><\/span>3940: [Usaco2015 Feb]Censoring<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a010 Sec\u00a0\u00a0Memory Limit:\u00a0128 MB<\/span><\/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>Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have plenty<\/div>\n<div>of material to read while waiting around in the barn during milking sessions. Unfortunately, the latest<\/div>\n<div>issue contains a rather inappropriate article on how to cook the perfect steak, which FJ would rather his<\/div>\n<div>cows not see (clearly, the magazine is in need of better editorial oversight).<\/div>\n<div>FJ has taken all of the text from the magazine to create the string S of length at most 10^5 characters.<\/div>\n<div>He has a list of censored words t_1 &#8230; t_N that he wishes to delete from S. To do so Farmer John finds<\/div>\n<div>the earliest occurrence of a censored word in S (having the earliest start index) and removes that instance<\/div>\n<div>of the word from S. He then repeats the process again, deleting the earliest occurrence of a censored word<\/div>\n<div>from S, repeating until there are no more occurrences of censored words in S. Note that the deletion of one<\/div>\n<div>censored word might create a new occurrence of a censored word that didn&#8217;t exist before.<\/div>\n<div>Farmer John notes that the censored words have the property that no censored word appears as a substring of<\/div>\n<div>another censored word. In particular this means the censored word with earliest index in S is uniquely<\/div>\n<div>defined.Please help FJ determine the final contents of S after censoring is complete.<\/div>\n<div>FJ\u628a\u6742\u5fd7\u4e0a\u6240\u6709\u7684\u6587\u7ae0\u6458\u6284\u4e86\u4e0b\u6765\u5e76\u628a\u5b83\u53d8\u6210\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e0d\u8d85\u8fc710^5\u7684\u5b57\u7b26\u4e32S\u3002\u4ed6\u6709\u4e00\u4e2a\u5305\u542bn\u4e2a\u5355\u8bcd\u7684\u5217\u8868\uff0c\u5217\u8868\u91cc\u7684n\u4e2a\u5355\u8bcd<\/div>\n<div>\u8bb0\u4e3at_1&#8230;t_N\u3002\u4ed6\u5e0c\u671b\u4eceS\u4e2d\u5220\u9664\u8fd9\u4e9b\u5355\u8bcd\u3002<\/div>\n<div>FJ\u6bcf\u6b21\u5728S\u4e2d\u627e\u5230\u6700\u65e9\u51fa\u73b0\u7684\u5217\u8868\u4e2d\u7684\u5355\u8bcd(\u6700\u65e9\u51fa\u73b0\u6307\u8be5\u5355\u8bcd\u7684\u5f00\u59cb\u4f4d\u7f6e\u6700\u5c0f)\uff0c\u7136\u540e\u4eceS\u4e2d\u5220\u9664\u8fd9\u4e2a\u5355\u8bcd\u3002\u4ed6\u91cd\u590d\u8fd9\u4e2a\u64cd\u4f5c\u76f4\u5230S\u4e2d<\/div>\n<div>\u6ca1\u6709\u5217\u8868\u91cc\u7684\u5355\u8bcd\u4e3a\u6b62\u3002\u6ce8\u610f\u5220\u9664\u4e00\u4e2a\u5355\u8bcd\u540e\u53ef\u80fd\u4f1a\u5bfc\u81f4S\u4e2d\u51fa\u73b0\u53e6\u4e00\u4e2a\u5217\u8868\u4e2d\u7684\u5355\u8bcd<\/div>\n<div>FJ\u6ce8\u610f\u5230\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u4e0d\u4f1a\u51fa\u73b0\u4e00\u4e2a\u5355\u8bcd\u662f\u53e6\u4e00\u4e2a\u5355\u8bcd\u5b50\u4e32\u7684\u60c5\u51b5\uff0c\u8fd9\u610f\u5473\u7740\u6bcf\u4e2a\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u5728S\u4e2d\u51fa\u73b0\u7684\u5f00\u59cb\u4f4d\u7f6e\u662f\u4e92\u4e0d\u76f8\u540c\u7684<\/div>\n<div>\u8bf7\u5e2e\u52a9FJ\u5b8c\u6210\u8fd9\u4e9b\u64cd\u4f5c\u5e76\u8f93\u51fa\u6700\u540e\u7684S<\/div>\n<pre><\/pre>\n<p>&nbsp;\n<\/p><\/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>The first line will contain S. The second line will contain N, the number of censored words. The next N lines contain the strings t_1 &#8230; t_N. Each string will contain lower-case alphabet characters (in the range a..z), and the combined lengths of all these strings will be at most 10^5.<\/div>\n<div>\u7b2c\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\u4e32S<\/div>\n<div>\u7b2c\u4e8c\u884c\u5305\u542b\u4e00\u4e2a\u6574\u6570N<\/div>\n<div>\u63a5\u4e0b\u6765\u7684N\u884c\uff0c\u6bcf\u884c\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u7b2ci\u884c\u7684\u5b57\u7b26\u4e32\u662ft_i<\/div>\n<p>&nbsp;\n<\/p><\/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>The string S after all deletions are complete. It is guaranteed that S will not become empty during the deletion process.<\/div>\n<div>\n<div>\u4e00\u884c\uff0c\u8f93\u51fa\u64cd\u4f5c\u540e\u7684S<\/div>\n<div><\/div>\n<\/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\">begintheescapexecutionatthebreakofdawn<br \/>\n 2<br \/>\n escape<br \/>\n execution<\/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\">beginthatthebreakofdawn<\/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<div class=\"content\">Gold<\/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;string&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 ll long long\r\n#define N 100010\r\nchar s[N],s1[N],ans[N];\r\nint fail[N],ch[N][26],dep[N];\r\nint n,rt=1,tot=1,q[N],w[N];\r\nvoid build()\r\n{\r\n    int h=0,t=0,x;\r\n    fail[rt]=rt;\r\n    for(int i=0;i&lt;26;i++)\r\n        if(ch[rt][i]==-1) ch[rt][i]=rt;\r\n        else \r\n        {\r\n            fail[ch[rt][i]]=rt;\r\n            q[++t]=ch[rt][i];\r\n        }\r\n    while(h&lt;t)\r\n    {\r\n        x=q[++h];\r\n        for(int i=0;i&lt;26;i++)\r\n            if(ch[x][i]==-1) ch[x][i]=ch[fail[x]][i];\r\n            else \r\n            {\r\n                fail[ch[x][i]]=ch[fail[x]][i];\r\n                q[++t]=ch[x][i];\r\n            }\r\n    }\r\n}\r\nint main()\r\n{\r\n    scanf(\"%s\",s+1);\r\n    memset(ch,-1,sizeof(ch));\r\n    scanf(\"%d\",&amp;n);\r\n    int len,x,t;\r\n    for(int i=1;i&lt;=n;i++)\r\n    {\r\n        scanf(\"%s\",s1+1);\r\n        len=strlen(s1+1);x=rt;\r\n        for(int i=1;i&lt;=len;i++)\r\n        {\r\n            t=s1[i]-'a';\r\n            if(ch[x][t]==-1) ch[x][t]=++tot;\r\n            x=ch[x][t];\r\n        }\r\n        dep[x]=len;\r\n    }\r\n    build();\r\n    x=rt;len=strlen(s+1);tot=0;w[0]=rt;\r\n    for(int i=1;i&lt;=len;i++)\r\n    {\r\n        ans[++tot]=s[i];\r\n        x=ch[x][s[i]-'a'];w[tot]=x;\r\n        if(dep[x]){tot-=dep[x];x=w[tot];}\r\n    }\r\n    for(int i=1;i&lt;=tot;i++) printf(\"%c\",ans[i]);puts(\"\");\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 3940: [Usaco2015 Feb]Censoring Time Limit:\u00a010 Se [&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":[54,19],"class_list":["post-509","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-ac","tag-19"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/509","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=509"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/509\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/509\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}