{"id":1795,"date":"2021-10-21T13:46:46","date_gmt":"2021-10-21T05:46:46","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1795"},"modified":"2021-10-21T19:14:35","modified_gmt":"2021-10-21T11:14:35","slug":"facebook-hacker-cup-2021-round-1","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/facebook-hacker-cup-2021-round-1\/","title":{"rendered":"Facebook Hacker Cup 2021 Round 1"},"content":{"rendered":"<p>A1.<br \/>\n\u7ed9\u5b9a\u4e00\u4e2a &#8217;01-&#8216; \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s\uff0c\u8bbe f(s) \u4e3a\u5ffd\u7565\u6389 s \u4e2d\u6240\u6709 &#8216;-&#8216; \u5b57\u7b26\u540e\uff0c\u76f8\u90bb\u5b57\u7b26\u53d1\u751f\u53d8\u6362\u7684\u6b21\u6570\u3002<br \/>\n\u6c42 f(s)\u3002<br \/>\n\u626b\u4e00\u904d\u5373\u53ef\u3002<\/p>\n<p>A2<br \/>\n\u7edf\u8ba1\u6240\u6709 s \u7684\u5b50\u4e32\u7684 f \u503c\u3002<br \/>\n\u7edf\u8ba1\u76f8\u90bb\u7684 &#8217;01&#8217; pair \u7684\u8d21\u732e\u5373\u53ef\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = int(1e6) + 9;\r\nchar s&#x5B;N];\r\nint n;\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    Rush {\r\n        RD(n); RS(s);\r\n        Int z = 0;\r\n        char lc = '?'; \/\/ \u4e0a\u4e00\u4e2a\u5b57\u7b26\r\n        int lp = 0; \/\/ \u4e0a\u4e00\u4e2a\u5b57\u7b26\u7684\u4f4d\u7f6e\r\n\r\n        REP(i, n) {\r\n            char c = s&#x5B;i];\r\n            if(c != 'F') {\r\n                if (lc != c) {\r\n                    if(lc != '?') z += Int(lp) * (n-i);\r\n                    lc = c;\r\n                }\r\n                lp = i+1;\r\n            }\r\n        }\r\n        OT(z);\r\n    }\r\n}\r\n<\/pre>\n<p>A3<br \/>\ns \u4e2d\u8fd8\u5305\u542b &#8216;.&#8217; \u5b57\u7b26\uff0c\u5982\u679c\u51fa\u73b0 &#8216;.&#8217; \u5b57\u7b26\uff0c\u5219\u7528\u6b64\u524d\u7684\u5b57\u7b26\u4e32\u66ff\u6362 &#8216;.&#8217; \u4f4d\u7f6e\uff0c\u8be2\u95ee A2\u3002<\/p>\n<p>\u5ef6\u7eed A2 \u7684\u601d\u8def\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6bcf\u4e2a pair \u7edf\u8ba1\u51fa\u5de6\u8fb9\u548c\u53f3\u8fb9\u5206\u522b\u6709\u591a\u5c11\u5b57\u7b26\u3002<br \/>\n\u8fd9\u4e2a\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u662f\u6bcf\u4e2a &#8216;.&#8217; \u5185\u90e8\u8fd8\u4f1a\u51fa\u73b0\u5f88\u591a pair\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u8fd9\u4e9b\u5185\u90e8\u7684 pair \u4e5f O(1) \u65f6\u95f4\u7edf\u8ba1\u3002<br \/>\n\u8fd9\u6837\u9996\u5148\u6211\u4eec\u9700\u8981\u6539\u8fdb A2 \u7684\u7b97\u6cd5\uff0c\u518d\u5f00\u4e00\u4e2a ls \u53d8\u91cf\u8bb0\u5f55\u524d\u9762\u6240\u6709 pair \u7684\u8d21\u732e\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u4e0d\u652f\u6301\u540e\u7eed\u957f\u5ea6\u7684\u60c5\u51b5\u4e0b incremental \u7684\u7ef4\u62a4\u7b54\u6848\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = int(1e6) + 9;\r\nchar s&#x5B;N];\r\nint n;\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    Rush {\r\n        RD(n); RS(s);\r\n        Int z = 0;\r\n        char lc = '?'; \/\/ \u4e0a\u4e00\u4e2a\u5b57\u7b26\r\n        int lp = 0; \/\/ \u4e0a\u4e00\u4e2a\u5b57\u7b26\u7684\u4f4d\u7f6e\r\n        Int ls = 0; \/\/ \u53f3\u8fb9\u65b0\u589e\u52a0\u4e00\u4e2a\u5b57\u7b26\u65f6\u7b54\u6848\u7684\u589e\u91cf\u3002\r\n\r\n        REP(i, n) {\r\n            z += ls;\r\n            char c = s&#x5B;i];\r\n            if (c != 'F') {\r\n                if (lc != '?' &amp;&amp; lc != c) {\r\n                    z += lp;\r\n                    ls += lp;\r\n                }\r\n                lp = i+1;\r\n                lc = c;\r\n            }\r\n        }\r\n        OT(z);\r\n    }\r\n}\r\n<\/pre>\n<p>\u8fdb\u4e00\u6b65\u8003\u8651 &#8216;.&#8217; \u7684\u5f71\u54cd\uff0c\u6211\u4eec\u4e0d\u4ec5\u9700\u8981\u77e5\u9053\u5f53\u53f3\u8fb9\u65b0\u589e\u52a0\u4e00\u4e2a\u5b57\u7b26\u65f6\u7684\u589e\u91cf ls\uff0c\u8fd8\u9700\u8981\u5bf9\u79f0\u7684\uff0c\u77e5\u9053\u5f53\u5de6\u8fb9\u65b0\u589e\u52a0\u4e00\u4e2a\u5b57\u7b26\u65f6\u7684\u589e\u91cf rs\uff0c<br \/>\n\u90a3\u4e48\u65b0\u7684\u7b54\u6848\u5c31\u662f 2z + len(ls+rs)\uff0c\u8fd8\u8981\u8003\u8651\u5408\u5e76\u7684\u4f4d\u7f6e\u4f1a\u4e0d\u4f1a\u4ea7\u751f\u4e00\u7ec4\u65b0\u7684 pair\u3002<br \/>\n\u56e0\u6b64\u8fd8\u9700\u8981\u7ef4\u62a4\u5de6\u53f3\u7b2c\u4e00\u4e2a\u5b57\u7b26\u662f\u4ec0\u4e48\u548c\u6240\u5728\u4f4d\u7f6e\u4ee5\u53ca\u4e00\u5171\u6709\u591a\u5c11 pair\u3002\u5404\u79cd\u7ef4\u62a4\u5373\u53ef\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = int(1e6) + 9;\r\nchar s&#x5B;N];\r\nint n;\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    Rush {\r\n        RD(n); RS(s);\r\n        Int z = 0;\r\n        char lc = '?', rc = '?'; \/\/\r\n        Int lp = 0, rp = 0, ct = 0;\r\n        Int ls = 0, rs = 0;\r\n        Int len = 0;\r\n\r\n        REP(i, n) {\r\n            char c = s&#x5B;i];\r\n            if (c == '.') {\r\n\r\n                z = z*2 + len*(ls+rs);\r\n                ls = ls*2 + len*ct;\r\n                rs = rs*2 + len*ct;\r\n                ct *= 2;\r\n\r\n                if (lc != rc) {\r\n                    ct += 1; ls += lp; rs += (len-rp+1);\r\n                    z += lp * (len-rp+1);\r\n                }\r\n                if (lc != '?') lp += len;\r\n                len *= 2;\r\n\r\n            } else {\r\n\r\n                z += ls;\r\n                len += 1;\r\n\r\n                if (c != 'F') {\r\n\r\n                    if (rc == '?') {\r\n                        rc = c, rp = len;\r\n                    }\r\n\r\n                    if (lc != '?' &amp;&amp; lc != c) {\r\n                        z += lp;\r\n                        ls += lp;\r\n                        ct += 1;\r\n                    }\r\n                    lp = len;\r\n                    lc = c;\r\n                }\r\n\r\n                rs += ct;\r\n            }\r\n        }\r\n        OT(z);\r\n    }\r\n}\r\n<\/pre>\n<p>C.<br \/>\n\u611f\u89c9\u662f\u6811\u5f62 dp \u57fa\u672c\u529f\u9898\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5e94\u8be5\u662f dfs() \u4e24\u6b21\uff0c<br \/>\n\u4e00\u6b21\u5f97\u5230\u5b50\u6811\u7684 dp \u72b6\u6001\uff0c\u4e00\u6b21\u5f97\u5230\u5b50\u6811\u5916\u7684 dp \u72b6\u6001\uff0c\u4f46\u662f\u6bd4\u8d5b\u65f6\u601d\u8def\u6bd4\u8f83\u6df7\u4e71\u3002<\/p>\n<p>\u8d5b\u540e\u8bfb\u4e86\u4e00\u4e0b <a href=\"https:\/\/www.facebook.com\/async\/codingproblems\/download\/submission\/source_code\/?submission_id=1114969585702102\">nhb \u7684\u4ee3\u7801<\/a>\uff0c\u53d1\u73b0\u5ffd\u7565\u4e86\u4e00\u4e2a\u91cd\u8981\u5f97\u6761\u4ef6\uff0c\u5c31\u662f\u8fb9\u6743 &lt;= 20\u3002\u3002\u3002<br \/>\n\u7136\u540e\u5c31\u53ef\u4ee5\u76f4\u63a5\u66b4\u529b\u52a0\u7ef4\u4e86\u3002\u3002\u56e7\u3002<\/p>\n<p>\u5f53\u7136\u8fb9\u5206\u6cbb\u4e5f\u53ef\u4ee5\uff0c\u53c2\u8003 <a href=\"https:\/\/www.facebook.com\/async\/codingproblems\/download\/submission\/source_code\/?submission_id=1959733264185747\">neal wu \u7684\u4ee3\u7801<\/a>\u3002<\/p>\n<p>\u4e0d\u77e5\u9053\u6ca1\u6709\u8fb9\u6743\u7684\u9650\u5236\u8fd8\u80fd\u4e0d\u80fd\u505a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A1. \u7ed9\u5b9a\u4e00\u4e2a &#8217;01-&#8216; \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s\uff0c\u8bbe f(s) \u4e3a\u5ffd\u7565\u6389 s \u4e2d\u6240\u6709 &#8216;-&#8216; \u5b57\u7b26\u540e\uff0c\u76f8\u90bb\u5b57\u7b26\u53d1\u751f\u53d8\u6362\u7684\u6b21\u6570\u3002 \u6c42 f(s)\u3002 \u626b\u4e00\u904d\u5373\u53ef\u3002 A2 \u7edf\u8ba1\u6240\u6709 s \u7684\u5b50\u4e32\u7684 f \u503c\u3002 \u7edf\u8ba1\u76f8\u90bb\u7684 &#8217;01&#8217; pair \u7684\u8d21\u732e\u5373\u53ef\u3002 const int N = int(1e6) + 9; char s&#x5B;N]; int n; int main() { #ifndef ONLINE_JUDGE freopen(&quot;in.txt&quot;,&quot;r&quot;,stdin); freopen(&quot;out.txt&quot;,&quot;w&quot;,stdout); #endif Rush { RD(n); RS(s); Int z = 0; char lc = &#8216;?&#8217;; [&hellip;]<\/p>\n","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":[1],"tags":[],"class_list":["post-1795","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-sX","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1795","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=1795"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1795\/revisions"}],"predecessor-version":[{"id":1796,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1795\/revisions\/1796"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}