{"id":871,"date":"2021-11-14T16:52:52","date_gmt":"2021-11-14T08:52:52","guid":{"rendered":"https:\/\/blog.cruciferslab.net\/?p=871"},"modified":"2022-11-23T14:06:55","modified_gmt":"2022-11-23T06:06:55","slug":"gks-2021-round-h","status":"publish","type":"post","link":"https:\/\/blog.cruciferslab.net\/?p=871","title":{"rendered":"GKS 2021 Round H"},"content":{"rendered":"\n<p>\u56e0\u70ba\u5404\u7a2e\u539f\u56e0\uff0c\u4eca\u5929\u662f\u5728\u8001\u5bb6\u88e1\u53c3\u6230\uff0c\u90a3 11am ~ 2pm \u9019\u6bb5\u6642\u9593\u786c\u662f\u5361\u4e86\u4e00\u500b\u5348\u98ef\u6642\u9593\u5c31\u6709\u9ede\u5fae\u5999\u4e86\u3002\u9084\u597d\u4e2d\u9910\u6c92\u6709\u803d\u8aa4\u5230\u591a\u5c11 (\u6b63\u597d\u62ff\u4f86\u8b93\u6211\u60f3\u984c\u76ee)\uff0c\u6240\u4ee5\u53c3\u6230\u7d50\u679c\u9084\u7b97\u6eff\u610f\u3002<\/p>\n\n\n\n<p>\u9019\u6b21\u6210\u7e3e\u662f 95 \u540d\uff0c\u4e09\u56db\u5169\u984c\u7684\u5927\u6e2c\u8cc7\u90fd TLE\uff1b\u4e0d\u904e\u9019\u5169\u984c\u770b\u8d77\u4f86\u5c31\u662f\u9019\u5834\u7684\u9b54\u738b\u4e86\uff0c\u6240\u4ee5\u96d6\u7136\u53ea\u62ff 62 \u5206\uff0c\u4f46\u540d\u6b21\u9084\u6709\u5728\u524d\u767e\u3002\u5206\u6578\u622a\u5716\u4ee5\u4e0b\u6709\u96f7\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"146\" src=\"https:\/\/blog.cruciferslab.net\/wp-content\/uploads\/2021\/11\/image-1024x146.png\" alt=\"\" class=\"wp-image-873\" srcset=\"https:\/\/blog.cruciferslab.net\/wp-content\/uploads\/2021\/11\/image-1024x146.png 1024w, https:\/\/blog.cruciferslab.net\/wp-content\/uploads\/2021\/11\/image-300x43.png 300w, https:\/\/blog.cruciferslab.net\/wp-content\/uploads\/2021\/11\/image-150x21.png 150w, https:\/\/blog.cruciferslab.net\/wp-content\/uploads\/2021\/11\/image-768x109.png 768w, https:\/\/blog.cruciferslab.net\/wp-content\/uploads\/2021\/11\/image-1536x218.png 1536w, https:\/\/blog.cruciferslab.net\/wp-content\/uploads\/2021\/11\/image.png 1849w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Q1. Transform the String<\/h2>\n\n\n\n<p>\u9019\u984c\u6c92\u4ec0\u9ebc\u96e3\u5ea6\uff0c\u5c31\u5f88\u7c21\u55ae\u7684\u770b\u6bcf\u500b\u5b57\u79fb\u5230\u54ea\u500b\u4f4d\u7f6e\u6700\u8fd1\u800c\u5df2\u3002\u8003\u616e\u5230\u8f38\u5165\u6703\u5f88\u9577\u7684\u72c0\u6cc1\uff0c\u56e0\u6b64\u5c31\u5148\u9810\u8655\u7406\u4e00\u6b21\uff0c\u7b97\u597d\u6240\u6709 26 \u500b\u5b57\u6bcd\u5404\u8981\u591a\u5c11\u6b21\u8b8a\u52d5\u5230\u9ede\uff0c\u7136\u5f8c\u5b57\u4e32\u9032\u4f86\u5c31\u6383\u4e00\u908a\u52a0\u904e\u53bb\u5c31\u597d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Q2. Painter<\/h2>\n\n\n\n<p>\u5982\u679c\u80fd\u770b\u51fa\u4e09\u539f\u8272\u5176\u5be6\u662f\u500b\u5225\u7368\u7acb\u7684\u8a71\uff0c\u9019\u984c\u5c31\u5f88\u7c21\u55ae\u4e86\uff1b\u5c0d\u4e09\u539f\u8272\u53bb\u6c42\u51fa\u9023\u7e8c\u683c\u5b50\u7684\u500b\u6578\u3002\u70ba\u4e86\u4e0d\u8981\u88ab\u5224\u65b7\u5f0f\u7d46\u4f4f\uff0c\u8f38\u5165\u7684\u5b57\u4e32\u5148\u8f49\u6210 0~7 \u7684\u6578\u5b57\u4e4b\u5f8c\uff0c\u7528 bitmask \u5206\u958b\u6383\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Q3. Silly Substitutions<\/h2>\n\n\n\n<p>\u9019\u984c\u7d46\u4f4f\u6211\u6709\u9ede\u5927\uff0c\u539f\u672c\u662f\u6709\u60f3\u505a\u5927\u6e2c\u8cc7\u7684\u4f46\u5305\u542b\u5348\u98ef\u6642\u9593\u60f3\u4e86\u60f3\u4e4b\u5f8c\u767c\u73fe\u5806\u758a\u6cd5\u6709\u597d\u591a\u7279\u6b8a\u72c0\u6cc1\u8981\u8655\u7406\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u53ea\u8981\u904e\u5c0f\u6e2c\u8cc7\u7684\u8a71\uff0c\u6700\u7c21\u55ae\u7684\u505a\u6cd5\u5927\u6982\u53ea\u8981\u4e8c\u5341\u884c\u5de6\u53f3\u5c31\u80fd\u641e\u5b9a\uff0c\u76f4\u63a5\u547c\u53eb\u4e00\u822c\u7684\u5b57\u4e32\u8655\u7406\u51fd\u6578\u5c31\u53ef\u4ee5\u4e86\uff1b\u554f\u984c\u5728\u65bc\u9019\u7a2e\u51fd\u6578\u547c\u53eb\u55ae\u6b21\u6642\u9593\u662f \\(O(n)\\)\uff0c\u5168\u90e8\u6700\u591a\u7684\u64cd\u4f5c\u6578\u4e5f\u662f \\(O(n)\\)\uff0c\u7e3d\u8a08\u5c31\u662f \\(O(n^2)\\)\u3002<\/p>\n\n\n\n<p>\u6211\u6240\u8b02\u7684\u5806\u758a\u6cd5\u5c31\u662f\u6578\u5b57\u9032\u4f86\u6642\u5c31\u76f4\u63a5\u5f80\u524d\u7d50\u7b97\uff0c\u8655\u7406\u5b8c\u4e4b\u5f8c\u518d\u770b\u4e0b\u4e00\u500b\u6578\u5b57\u3002\u4e3b\u8981\u7406\u7531\u662f\uff0c\u5e7e\u4e4e\u6bcf\u500b\u6578\u5b57\u90fd\u5f37\u70c8\u504f\u597d\u548c\u524d\u9762\u4e00\u8d77\u7d50\u7b97 (\u4f8b\u5982\uff1a123 \u7684 2 \u6703\u5148\u8ddf 1 \u7d50\u7b97\uff0c\u53d6\u4ee3\u6210 33\uff0c\u800c\u4e0d\u6703\u5411\u5f8c\u627e 23 \u53d6\u4ee3\u8b8a\u6210 14)\uff0c\u56e0\u6b64\u5148\u9032\u4f86\u7684\u5c31\u80fd\u5148\u8655\u7406\u3002<\/p>\n\n\n\n<p>\u554f\u984c\u5c31\u5728\u4e0a\u9762\u7684\u300c\u5e7e\u4e4e\u300d\u5169\u500b\u5b57\uff1a\u6700\u5bb9\u6613\u60f3\u5230\u7684\u554f\u984c\u662f 0\uff0c\u6bd4\u8d77 90 \u5b83\u66f4\u559c\u6b61 01\uff0c\u6240\u4ee5 901 \u6703\u8b8a\u6210 92 \u800c\u4e0d\u662f 11\uff1b\u4e0d\u904e\u4e0d\u53ea 0 \u6709\u9019\u554f\u984c\uff1a89101 \u7684\u4e2d\u9593\u7684 1\uff0c\u5b83\u61c9\u8a72\u8981\u8ddf\u5f8c\u9762 01 \u53d6\u4ee3\u6210\u7684 2 \u4e00\u8d77\u8b8a\u6210 3\uff0c\u6240\u4ee5 89101 \u61c9\u8a72\u8981\u8b8a\u6210 03\uff0c\u4f46\u5982\u679c\u4e2d\u9593 1 \u5148\u548c\u524d\u9762 89 \u53d6\u4ee3\u6210\u7684 0 \u8b8a\u6210 2 \u7684\u8a71\uff0c\u7d50\u679c\u5c31\u662f 22\u3002<\/p>\n\n\n\n<p>\u984c\u89e3\u88e1\u63d0\u5230\u7684\u4e32\u5217\u6cd5\u5176\u5be6\u4e5f\u6709\u60f3\u5230\uff0c\u4f46\u56e0\u70ba\u4e0d\u592a\u597d\u78ba\u8a8d\u8981\u600e\u9ebc\u7dad\u8b77\u60f3\u8981\u53d6\u4ee3\u7684\u4f4d\u7f6e\u6240\u4ee5\u5c31\u66ab\u6642\u653e\u4e0b\u4e86\u3002\u6700\u5f8c\u662f\u5728\u958b\u8cfd\u5169\u5c0f\u6642\u5f8c\u6c7a\u5b9a\u7b97\u4e86\u53bb\u505a Q4\uff0c\u628a\u53ea\u904e\u5c0f\u6e2c\u8cc7\u7684\u89e3\u9001\u4e86\u4e0a\u53bb\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Q4. Dependent Events<\/h2>\n\n\n\n<p>\u9019\u984c\u770b\u8d77\u4f86\u5f88\u53ef\u6015\uff0c\u4f46\u5176\u5be6\u53ef\u4ee5\u8aaa\u9019\u984c\u5df2\u7d93\u628a\u7b97\u5f0f\u5beb\u7d66\u4f60\u770b\u4e86\u3002\u57fa\u672c\u6982\u5ff5\u5f88\u7c21\u55ae\uff1a\u4e09\u500b\u4e8b\u4ef6 \\(A, B, C\\) \u5982\u679c\u5728\u540c\u4e00\u689d\u4f9d\u8cf4\u93c8\u4e0a\u7684\u8a71\uff0c\u6211\u5011\u6709\uff1a\\[P(C|A)=P(C|B)P(B|A)+P(C|B^c)P(B^c|A)\\] \u9019\u5c31\u662f\u984c\u76ee\u4e2d\u9593\u7684 \\(0.2\\times0.8+0.4\\times0.2=0.24\\) \u5728\u7b97\u7d66\u4f60\u770b\u7684\u3002<\/p>\n\n\n\n<p>\u81f3\u65bc\u7b2c\u4e00\u984c\u7684 3 5 \u9019\u7a2e\u6e2c\u8cc7\u53c8\u5982\u4f55\uff1f\u5b83\u5011\u7684<a href=\"https:\/\/en.wikipedia.org\/wiki\/Lowest_common_ancestor\" data-type=\"URL\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/Lowest_common_ancestor\">\u6700\u5c0f\u5171\u540c\u7956\u5148 (LCA)<\/a> \u662f\u4e8b\u4ef6 1\uff0c\u5728\u4e8b\u4ef6 1 \u7d66\u5b9a\u767c\u4e0d\u767c\u751f\u4e4b\u5f8c\u5169\u8005\u662f\u7368\u7acb\u7684\uff0c\u56e0\u6b64\u6211\u5011\u6709 \\[\\begin{aligned}P(E_3\\cap E_5)&amp;=P(E_3\\cap E_5|E_1)P(E_1)+P(E_3\\cap E_5|E_1^c)P(E_1^c)\\\\&amp;=(P(E_3|E_1)\\times P(E_5|E_1))P(E_1)+(P(E_3|E_1^c)\\times P(E_5|E_1^c))P(E_1^c)\\end{aligned}\\] \u4e2d\u9593\u7684\u56db\u500b\u689d\u4ef6\u6a5f\u7387\u5c31\u80fd\u7528\u548c\u4e0a\u9762\u4e00\u6a23\u7684\u7b97\u6cd5\u6c42\u51fa\u4f86\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u4e00\u500b\u53ef\u6015\u7684\u6771\u897f\u662f\u9019\u984c\u7684\u5947\u602a\u8f38\u51fa\u683c\u5f0f\uff1a\u5b83\u8981\u6c42\u5c07\u4e00\u500b\u5206\u6578 \\(\\frac{p}{q}\\) \u8868\u793a\u6210\u4e00\u500b\u6574\u6578 \\(R\\)\uff0c\u4f7f\u5f97 \\(R\\times q\\equiv p \\pmod{10^9+7}\\)\u3002\u6240\u4ee5\u6211\u5011\u597d\u50cf\u9700\u8981\u7528\u5206\u6578\u7b97\u51fa\u7b54\u6848\u4f86\u4e4b\u5f8c\uff0c\u518d\u7528\u6b50\u57fa\u91cc\u5fb7\u6f14\u7b97\u6cd5\u6c42\u4e58\u6cd5\u9006\u2026\u2026\u770b\u8d77\u4f86\u5c31\u662f\u4e00\u9663\u9ebb\u7169\u4e8b\u3002\u9019\u88e1\u7684\u95dc\u9375\u662f\u6ce8\u610f\u5230\uff0c\u56e0\u70ba\u7d66\u5b9a\u7684\u5206\u6578\u662f\u4ee5\u767e\u842c\u5206\u4e4b\u4e00\u70ba\u55ae\u4f4d\uff0c\u6240\u4ee5\u6240\u6709\u7684\u5206\u6bcd\u90fd\u53ea\u6703\u6709 2 \u548c 5 \u7684\u56e0\u6578\uff0c\u56e0\u6b64\u6211\u5011\u53ef\u4ee5\u76f4\u63a5\u628a\u7d66\u5b9a\u7684\u6a5f\u7387\u503c\u5c31\u8b8a\u6210\u9019\u7a2e R \u8868\u793a\u6cd5\uff0c\u7136\u5f8c\u6240\u6709\u7684\u8a08\u7b97\u5168\u90e8\u90fd\u7528\u9019\u7a2e\u8868\u793a\u6cd5\u9032\u884c\uff0c\u6700\u5f8c\u51fa\u4f86\u7684\u7d50\u679c\u4e5f\u5c31\u81ea\u52d5\u662f\u9019\u7a2e\u578b\u5f0f\u4e86\u3002\u4f8b\u5982\uff1a\\[\\begin{aligned}0.2=\\frac{200,000}{1,000,000}=\\frac{1}{5}&amp;\\equiv400,000,003\\pmod{10^9+7}\\\\<br>0.8=1-0.2\\equiv1-400,000,003&amp;\\equiv600,000,005\\pmod{10^9+7}\\\\<br>0.4=2*0.2\\equiv2*400,000,003&amp;\\equiv800,000,006\\pmod{10^9+7}\\end{aligned}\\] \u9019\u6a23\u4e0a\u9762\u7684 \\(0.2\\times0.8+0.4\\times0.2=0.24\\) \u5c31\u8b8a\u6210\uff1a\\[\\begin{aligned}&amp;400,000,003\\times600,000,005+800,000,006\\times400,000,003\\\\=&amp;240,000,003,800,000,015+320,000,004,800,000,018\\\\\\equiv&amp;120,000,001+560,000,004\\\\=&amp;680,000,005\\pmod{10^9+7}\\\\0.24=&amp;\\frac{6}{25}\\equiv6\\times280,000,002\\\\=&amp;1,680,000012\\equiv680,000,005\\pmod{10^9+7}\\end{aligned}\\] \u78ba\u5be6\u662f\u6c42\u51fa\u6240\u8981\u7b54\u6848\u7684\u8868\u793a\u4e86\u3002<\/p>\n\n\n\n<p>\u6700\u5f8c\u4e00\u500b\u5c0f\u6642\u7684\u6642\u9593\u6574\u7406\u597d\u9019\u500b\u7b97\u6cd5\u518d\u628a\u5b83\u76f4\u63a5\u5beb\u6210\u7a0b\u5f0f\u5c31\u5dee\u4e0d\u591a\u7528\u5b8c\u4e86 (\u6211\u662f\u5728\u622a\u6b62\u524d\u56db\u5206\u9418\u4e0a\u50b3\u7684\uff0cLCA \u5beb\u7684\u662f\u6700\u7c21\u55ae\u7684 \\(O(n)\\) \u7b97\u6cd5)\uff0c\u6240\u4ee5\u5f88\u5bb9\u6613\u60f3\u50cf\u5730\u5927\u6e2c\u8cc7\u540c\u6a23 TLE \u4e86\u3002\u8981\u89e3\u6c7a\u9019\u500b TLE\uff0c\u6ce8\u610f\u5230\u6700\u5c0f\u5171\u540c\u7956\u5148\u7684\u8a08\u7b97\u8ddf\u6a5f\u7387\u8a08\u7b97\u6703\u5728\u540c\u6a23\u7684\u6a39\u5206\u652f\u4e0a\u8dd1\u5169\u6b21\uff0c\u56e0\u6b64\u53ef\u4ee5\u628a LCA \u66f4\u597d\u7684\u7b97\u6cd5 (\u9810\u8655\u7406 \\(O(n\\log n)\\)\uff0c\u67e5\u8a62 \\(O(\\log n)\\)) \u7576\u4e2d\u6a5f\u7387\u90e8\u4efd\u5c0d\u61c9\u7684\u8a08\u7b97\u4e5f\u5148\u7b97\u51fa\u4f86\uff0c\u9019\u6a23\u8dd1\u4e00\u6b21\u6a39\u5c31\u80fd\u4e00\u53e3\u6c23\u76f4\u63a5\u6c42\u51fa\u6240\u6c42\u4f86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c0f\u7d50<\/h2>\n\n\n\n<p>\u7ffb\u4e86\u4e00\u4e0b\u4e4b\u5f8c\u7684\u540d\u6b21\u624d\u5687\u4e00\u8df3\uff1a\u505a\u5b8c Q3 \u5169\u500b\u6e2c\u8cc7\u4f46 Q4 \u6c92\u505a\u7684 60 \u5206\u662f\u524d 225 \u540d\u2026\u2026\u3002\u7b97\u662f\u679c\u65b7\u653e\u68c4 Q3 \u5927\u7684\u56de\u5831\u5427\u3002<\/p>\n\n\n\n<p>\u90a3\u9ebc\u4eca\u5e74\u7684 Kickstart \u5c31\u5230\u6b64\u70ba\u6b62\u3002\u660e\u5e74\u2026\u2026\u8981\u770b\u72c0\u6cc1\uff0c\u4e4b\u5f8c\u6709\u53ef\u80fd\u7121\u6cd5\u53c3\u8cfd\uff0c\u4e0d\u904e\u73fe\u5728\u516b\u5b57\u4e5f\u90fd\u9084\u6c92\u4e00\u6487\u6240\u4ee5\u5c31\u9084\u662f\u5225\u591a\u8aaa\u5427\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u70ba\u5404\u7a2e\u539f\u56e0\uff0c\u4eca\u5929\u662f\u5728\u8001\u5bb6\u88e1\u53c3\u6230\uff0c\u90a3 11am ~ 2pm \u9019\u6bb5\u6642\u9593\u786c\u662f\u5361\u4e86\u4e00\u500b\u5348\u98ef\u6642\u9593\u5c31\u6709\u9ede\u5fae\u5999\u4e86\u3002\u9084\u597d\u4e2d\u9910 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,4],"tags":[],"class_list":["post-871","post","type-post","status-publish","format-standard","hentry","category-gcj","category-programming"],"_links":{"self":[{"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=\/wp\/v2\/posts\/871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=871"}],"version-history":[{"count":51,"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions"}],"predecessor-version":[{"id":1148,"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions\/1148"}],"wp:attachment":[{"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cruciferslab.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}