{"id":2029,"date":"2022-09-13T06:03:00","date_gmt":"2022-09-12T22:03:00","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=2029"},"modified":"2022-09-14T11:34:24","modified_gmt":"2022-09-14T03:34:24","slug":"educational-codeforces-round-135","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/educational-codeforces-round-135\/","title":{"rendered":"Educational Codeforces Round 135"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/codeforces.com\/contest\/1728\">https:\/\/codeforces.com\/contest\/1728<\/a><\/li>\n<li><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/562734265\">https:\/\/zhuanlan.zhihu.com\/p\/562734265<\/a><\/li>\n<\/ul>\n<h2>Problem D. Letter Picking<\/h2>\n<p>\u533a\u95f4\u535a\u5f08 dp\uff0c\u72b6\u6001 f[][]\uff0c\u4f46\u662f\u6bd4\u4e00\u822c\u7684\u535a\u5f08 dp \u8981\u7b80\u5355\uff0c\u8f6c\u79fb trivial\u3002<br \/>\n\u9996\u5148\u6211\u4eec\u53ef\u4ee5\u4e24\u8f6e\u64cd\u4f5c\u7ed1\u5b9a\u5728\u4e00\u8d77\u8f6c\u79fb\uff0c\u53ea\u8981\u8003\u8651\u957f\u5ea6\u4e3a\u5076\u6570\u7684\u72b6\u6001\uff0c\u5e76\u4e14\u4e5f\u4e0d\u7528\u8bb0\u5f55\u4e0a\u4e00\u8f6e\u9009\u4e86\u4ec0\u4e48\u5b57\u7b26\u3002<br \/>\n\u8fdb\u4e00\u6b65\u4e0d\u96be\u5f52\u7eb3\u51fa\u7ed3\u679c\u53ea\u6709\u53ef\u80fd\u662f\u5148\u624b\u80dc\u6216\u5e73\u5c40\uff0c\u8fdb\u4e00\u6b65\u7b80\u5316\u72b6\u6001\u548c\u8f6c\u79fb\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;lastweapon\/io&gt;\r\nusing namespace lastweapon;\r\n\r\nconst int N = int(2e3) + 9;\r\nchar s&#x5B;N]; bool f&#x5B;N]&#x5B;N];\r\nint n;\r\n\r\nint main() {\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    Rush {\r\n        n = strlen(RS(s));\r\n\r\n        REP(i, n+1) f&#x5B;i]&#x5B;i] = 0;\r\n\r\n        for(int l=2;l&lt;=n;l+=2) {\r\n            REP(i, n-l+1) {\r\n                int j = i+l;\r\n                bool ll = f&#x5B;i+2]&#x5B;j] || (s&#x5B;i] &gt; s&#x5B;i+1]);\r\n                bool lr = f&#x5B;i+1]&#x5B;j-1] || (s&#x5B;i] &gt; s&#x5B;j-1]);\r\n                bool rl = f&#x5B;i+1]&#x5B;j-1] || (s&#x5B;j-1] &gt; s&#x5B;i]);\r\n                bool rr = f&#x5B;i]&#x5B;j-2] || (s&#x5B;j-1] &gt; s&#x5B;j-2]);\r\n                f&#x5B;i]&#x5B;j] = (ll &amp;&amp; lr) || (rl &amp;&amp; rr);\r\n            }\r\n        }\r\n        puts(f&#x5B;0]&#x5B;n] ? &quot;Alice&quot; : &quot;Draw&quot;);\r\n    }\r\n}\r\n<\/pre>\n<h2>Problem E. Red-Black Pepper<\/h2>\n<ul>\n<li><a href=\"https:\/\/oi-wiki.org\/math\/number-theory\/bezouts\/\">https:\/\/oi-wiki.org\/math\/number-theory\/bezouts\/<\/a><\/li>\n<\/ul>\n<p>\u8c03\u6574\u6cd5\u3002\u5148\u8003\u8651\u5224\u5b9a\u6027\u95ee\u9898\uff0c\u7528\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u6c42\u4e22\u756a\u56fe\u65b9\u7a0b ax + by = n \u7279\u89e3\uff0c\u7136\u540e\u5224\u65ad\u662f\u5426\u5b58\u5728\u4e00\u7ec4\u89e3\u4f7f\u5f97 ax \u5728 [0, n] \u8303\u56f4\u5185\u5373\u53ef\u3002<\/p>\n<p>\u8003\u8651\u6700\u4f18\u5316\u95ee\u9898\uff0c\u6839\u636e\u8f93\u5165\uff0c\u53ef\u4ee5\u9884\u5904\u7406\u51fa\u5173\u4e8e ax \u7684\uff0c\u5b9a\u4e49\u57df\u4e3a [0, n] \u4e4b\u95f4\u6574\u6570\u7684\uff0c\u975e\u4e25\u683c\u51f8\u51fd\u6570 f\uff0c\u6240\u8c13\u975e\u4e25\u683c\u5c31\u662f\u53ef\u80fd\u4e2d\u95f4\u5b58\u5728\u4e00\u4e9b\u76f8\u7b49\u7684\u60c5\u51b5\uff0c\u6bd4\u5982\u6700\u503c\u53ef\u80fd\u4f1a\u662f\u4e00\u4e2a\u533a\u95f4\uff0c<br \/>\n\u4e0d\u8fc7\u7a0d\u540e\u4f1a\u770b\u5230\uff0c\u8fd9\u95ee\u9898\u5e76\u4e0d\u5927\u3002\u3002<\/p>\n<p>\u6bcf\u6b21\u8be2\u95ee\u7684\u76ee\u6807\u51fd\u6570\u7684\u5b9a\u4e49\u57df\u5219\u662f f \u51fd\u6570\u7684\u5b50\u96c6\uff0c\u4ee5\u7279\u89e3\u4e3a\u4e2d\u5fc3\uff0c\u6bcf\u6b21\u6b65\u957f\u4e3a lcm(a, b)\uff0c\u8fd9\u4e5f\u662f\u975e\u4e25\u683c\u51f8\u51fd\u6570\uff0c\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u9884\u5904\u7406\u51fa\u4e86\u5b83\u7684\u5bfc\u6570\uff0c\u6240\u4ee5\u53ef\u4ee5\u5728\u5bfc\u6570\u4e0a\u4e8c\u5206\u6c42\u6781\u503c\u3002<br \/>\n\u4e0d\u8fc7\u6211\u4eec\u80fd\u505a\u7684\u66f4\u597d\uff0c\u53ea\u8981\u68c0\u67e5\u6700\u503c\u9644\u8fd1\u7684\u4e24\u4e2a\u70b9\u7684\u51fd\u6570\u5f0f\u503c f(xl), f(xr) \u5373\u53ef\uff0c\u5177\u4f53\u6765\u8bf4\uff0c\u5047\u8bbe\u6211\u4eec\u9884\u5904\u7406\u9636\u6bb5\u4fdd\u7559\u7684\u662f\u6700\u503c\u7684\u53f3\u7aef\u70b9 x0\uff0c<br \/>\n\u90a3\u4e48\u5c31\u68c0\u67e5 xl &lt; x0 &lt;= xr\uff0c\u5982\u679c\u662f\u5de6\u7aef\u70b9\uff0c<br \/>\n\u5c31\u68c0\u67e5 xl &lt;= x0 &lt; xr\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;lastweapon\/io&gt;\r\nusing namespace lastweapon;\r\n\r\nconst int N = int(3e5) + 9;\r\nint a&#x5B;N], b&#x5B;N], x0; LL f&#x5B;N];\r\nint n;\r\n\r\nLL exgcd(LL a, LL b, LL &amp;x, LL &amp;y){\r\n    if (!b){\r\n        x = 1, y = 0;\r\n        return a;\r\n    }\r\n    LL d = exgcd(b, a % b, y, x);\r\n    y -= a \/ b * x;\r\n    return d;\r\n}\r\n\r\nLL query() {\r\n    LL a, b, x, y; RD(a, b);\r\n    LL d = exgcd(a, b, x, y);\r\n    if (n % d) return -1;\r\n    x *= n\/d*a; d = a\/d*b;\r\n    x -= ceil(max(0ll, x-x0), d) * d;\r\n    x += max(0ll, x0-x) \/ d * d;\r\n    LL z = -1; if (x &gt;= 0) checkMax(z, f&#x5B;x]);\r\n    x += d; if (x &lt;= n) checkMax(z, f&#x5B;x]);\r\n    return z;\r\n}\r\n\r\nvoid init() {\r\n    RD(n); LL s = 0; REP(i, n) RD(a&#x5B;i], b&#x5B;i]), s += b&#x5B;i];\r\n    REP(i, n) a&#x5B;i] -= b&#x5B;i]; sort(a, a+n, greater&lt;int&gt;());\r\n    f&#x5B;0] = s; REP(i, n) f&#x5B;i+1] = f&#x5B;i] + a&#x5B;i];\r\n    x0 = upper_bound(a, a+n, 0, greater&lt;int&gt;()) - a - 1;\r\n}\r\n\r\nint main() {\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    init(); Rush OT(query());\r\n}\r\n<\/pre>\n<h2>Problem F. Fishermen<\/h2>\n<p>\u3002\u3002\u3002\u5c45\u7136\u6bd4\u8d5b\u65f6\u53ea\u6709 &lt;10 \u4e2a\u4eba\u8fc7\uff0c\uff0c\uff0c\u4f46\u662f\u505a\u6cd5\u975e\u5e38\u7b80\u5355\u3002\u3002\u3002<br \/>\n\u9996\u5148\u53ef\u4ee5\u770b\u51fa\u662f\u4e2a\u6700\u4f18\u5339\u914d\u6a21\u578b\u3002\u3002\u7136\u540e\uff0c\u6743\u503c\u90fd\u5728\u5355\u4fa7\u7684\u9876\u70b9\u4e0a\uff0c\u4e8e\u662f\u53ef\u4ee5 sort \u4e4b\u540e\u76f4\u63a5\u8dd1 <a href=\"https:\/\/cp-algorithms.com\/graph\/kuhn_maximum_bipartite_matching.html#standard-implementation\">Kuhn&#8217;s \u7b97\u6cd5<\/a>\u3002\u3002\u3002\u8fd9\u662f\u4e2a\u6bd4\u8f83\u5e38\u89c1\u7684\u5957\u8def\u3002\u3002<br \/>\n\u7136\u540e\u518d\u52a0\u4e00\u4e2a\u4f18\u5316\u3002\u3002\u3002\u201cif you haven&#8217;t found an augmenting path, don&#8217;t reset the values representing which vertices were visited by the algorithm.\u201d<br \/>\n\u5c31\u8fc7\u4e86\u3002\u3002\u3002\u56e7\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;lastweapon\/io&gt;\r\nusing namespace lastweapon;\r\n\r\nconst int N = int(1e3) + 9, N2 = N*N;\r\nint a&#x5B;N], b&#x5B;N2], py&#x5B;N]; bool vis&#x5B;N2]; VI adj&#x5B;N2];\r\nint n, bn;\r\n\r\nbool dfs(int x) {\r\n    if (vis&#x5B;x]) return 0;\r\n    vis&#x5B;x] = 1;\r\n    for (auto y: adj&#x5B;x]) {\r\n        int xx = py&#x5B;y];\r\n        if (xx == -1 || dfs(xx)) {\r\n            py&#x5B;y] = x;\r\n            return 1;\r\n        }\r\n    }\r\n    return 0;\r\n}\r\n\r\nLL kuhn() {\r\n    LL z = 0; int c = 0;\r\n    fill(py, py+n, -1);\r\n    REP(i, bn) if (dfs(i)) {\r\n        z += b&#x5B;i]; fill(vis, vis+bn, 0);\r\n        ++c; if (c == n) break;\r\n\r\n    }\r\n    return z;\r\n}\r\n\r\nint main() {\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    RD(n); REP(i, n) {\r\n        RD(a&#x5B;i]); REP(j, n) b&#x5B;i*n+j] = a&#x5B;i]*(j+1);\r\n    }\r\n    bn = n*n; sort(b, b+bn); bn = unique(b, b+bn) - b;\r\n\r\n    REP(i, n) {\r\n        int t = 0; REP(j, n) {\r\n            t = lower_bound(b+t, b+bn, a&#x5B;i]*(j+1)) - b;\r\n            adj&#x5B;t].PB(i);\r\n        }\r\n    }\r\n    OT(kuhn());\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/codeforces.com\/contest\/1728 https:\/\/zhuanlan.zhihu.com\/p\/562734265 Problem D. Letter Picking \u533a\u95f4\u535a\u5f08 dp\uff0c\u72b6\u6001 f[][]\uff0c\u4f46\u662f\u6bd4\u4e00\u822c\u7684\u535a\u5f08 dp \u8981\u7b80\u5355\uff0c\u8f6c\u79fb trivial\u3002 \u9996\u5148\u6211\u4eec\u53ef\u4ee5\u4e24\u8f6e\u64cd\u4f5c\u7ed1\u5b9a\u5728\u4e00\u8d77\u8f6c\u79fb\uff0c\u53ea\u8981\u8003\u8651\u957f\u5ea6\u4e3a\u5076\u6570\u7684\u72b6\u6001\uff0c\u5e76\u4e14\u4e5f\u4e0d\u7528\u8bb0\u5f55\u4e0a\u4e00\u8f6e\u9009\u4e86\u4ec0\u4e48\u5b57\u7b26\u3002 \u8fdb\u4e00\u6b65\u4e0d\u96be\u5f52\u7eb3\u51fa\u7ed3\u679c\u53ea\u6709\u53ef\u80fd\u662f\u5148\u624b\u80dc\u6216\u5e73\u5c40\uff0c\u8fdb\u4e00\u6b65\u7b80\u5316\u72b6\u6001\u548c\u8f6c\u79fb\u3002 #include &lt;lastweapon\/io&gt; using namespace lastweapon; const int N = int(2e3) + 9; char s&#x5B;N]; bool f&#x5B;N]&#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 { n = strlen(RS(s)); REP(i, n+1) f&#x5B;i]&#x5B;i] = 0; for(int [&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-2029","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-wJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2029","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=2029"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2029\/revisions"}],"predecessor-version":[{"id":2030,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2029\/revisions\/2030"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=2029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=2029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=2029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}