{"id":1205,"date":"2024-10-06T09:00:00","date_gmt":"2024-10-06T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1205"},"modified":"2024-09-07T12:58:00","modified_gmt":"2024-09-07T04:58:00","slug":"zerojudge-e289","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-e289\/","title":{"rendered":"ZeroJudge E289: Beautiful Ribbons"},"content":{"rendered":"\n\n\n<p>\u4f60\u6709\u4e00\u689d\u5f69\u8679\u8272\u7684\u5f69\u5e36\uff0c\u4f46\u662f\u56e0\u70ba\u5b83\u662f\u7570\u4e16\u754c\u4f86\u7684\u5f69\u5e36\uff0c\u6240\u4ee5\u53ef\u80fd\u4e0d\u53ea 7 \u500b\u984f\u8272 (\u7570\u4e16\u754c\u6709\u53ef\u80fd\u6709 87 \u8272\u7684\u5f69\u8679)\uff0c\u4f60\u6709\u4e00\u500b\u5b9a\u7fa9\u5f69\u5e36\u7f8e\u9e97\u5ea6\u7684\u6a19\u6e96\uff0c\u4f60\u5b9a\u7fa9\u4e00\u689d\u5f69\u5e36\u7684\u7f8e\u9e97\u5ea6\u70ba\u5b83\u6240\u64c1\u6709\u7684\u9577\u5ea6\u70ba M \u4e14\u6709 M \u7a2e\u984f\u8272\u7684\u5b50\u5340\u9593\u6578\u91cf\u3002<\/p>\n\n\n\n<p>\u73fe\u5728\u4f60\u9700\u8981\u5beb\u4e00\u500b\u7a0b\u5f0f\u4f86\u8a08\u7b97\u4e00\u500b\u5b57\u4e32\u7684\u7f8e\u9e97\u5ea6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u7b2c\u4e00\u884c\u6709\u5169\u500b\u6578\u5b57 M \u548c N\uff0c\u4ee3\u8868\u5b9a\u7fa9\u7684\u5b50\u5340\u9593\u9577\u5ea6\u548c\u5f69\u5e36\u9577\u5ea6\u3002<br>\u7b2c\u4e8c\u884c\u6709 N \u500b\u6578\u5b57\u4ee3\u8868\u5f69\u5e36\u7684\u984f\u8272\u3002<\/td><td>\u8f38\u51fa\u9019\u689d\u5f69\u5e36\u7684\u7f8e\u9e97\u5ea6\u3002<\/td><\/tr><tr><td>3 7<br>1 2 3 5 4 5 4<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u56e0\u70ba\u6578\u5b57\u6700\u5927\u6703\u662f 10 \u7684 150 \u6b21\u65b9\uff0c\u6240\u4ee5\u8981\u7528\u5b57\u4e32\u7684\u65b9\u5f0f\u4f86\u6536\u5f69\u5e36\u7684\u6578\u5b57\u3002\u4f7f\u7528 Map \u4f86\u7d00\u9304\u6bcf\u500b\u5340\u9593\u7684\u6578\u5b57\u6578\u91cf\uff0c\u4e26\u4e14\u5ba3\u544a\u4e00\u500b\u8b8a\u6578 number \u4f86\u7d00\u9304\u76ee\u524d\u7684\u5340\u6bb5\u4e2d\u6709\u591a\u5c11\u500b\u4e0d\u540c\u7684\u6578\u5b57\u3002<\/p>\n\n\n\n<p>\u8dd1\u4e00\u500b For\u8ff4\u5708 \u5f9e 0 \u5230 N-1\uff0c\u4e26\u4e14\u6bcf\u6b21\u90fd\u5c07\u65b0\u7684\u8cc7\u6599\u7d00\u9304\u5230 Map \u4e2d\u4e26\u4e14\u628a\u6700\u5de6\u908a\u7684\u8cc7\u6599\u505a\u522a\u9664\uff0c\u5982\u679c\u522a\u9664\u7684\u8cc7\u6599\u4e2d\u7684 Map \u503c\u662f 0\uff0c\u90a3\u5c31 number&#8211;\uff0c\u4ee3\u8868\u5340\u6bb5\u4e2d\u5c11\u4e86\u4e00\u500b\u4e0d\u540c\u7684\u6578\u5b57\u3002\u4e26\u4e14\u5982\u679c\u65b0\u52a0\u5165\u7684\u6578\u5b57\u7684 Map \u503c\u662f 1\uff0c\u4ee3\u8868\u662f\u4e00\u500b\u5168\u65b0\u7684\u6578\u5b57 number++\uff0c\u6bcf\u6b21\u8ff4\u5708\u90fd\u8981\u5224\u65b7 number \u662f\u5426\u7b49\u65bc M\uff0c\u5982\u679c\u6709\u7b49\u65bc\u7684\u8a71\u5c31\u5c07\u7b54\u6848 +1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e289\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge e289: \u7f8e\u9e97\u7684\u5f69\u5e36<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;map&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int M, N;\n    string num[200000] = {};\n    map&lt;string, int&gt;appear;\n    cin &gt;&gt; M &gt;&gt; N;\n    for (int i = 0; i&lt;N; i++) {\n        cin &gt;&gt; num[i];\n    }\n    int count = 0, last = 0, ans = 0, number = 0;\n    for (int i = 0; i&lt;N; i++) {\n        const string current = num[i];\n        if (count &lt;= M-1) {\n            appear[current]++;\n            count++;\n            if (appear[current] == 1) number++;\n            if (number == M) ans++;\n        }\n        else {\n            appear[num[last]]--;\n            if (appear[num[last]] == 0) number--;\n            appear[current]++;\n            if (appear[current] == 1) number++;\n            last++;\n            if (number == M) ans++;\n        }\n    }\n    cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge E289\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u6709\u4e00\u689d\u5f69\u8679\u8272\u7684\u5f69\u5e36\uff0c\u4f46\u662f\u56e0\u70ba\u5b83\u662f\u7570\u4e16\u754c\u4f86\u7684\u5f69\u5e36\uff0c\u6240\u4ee5\u53ef\u80fd\u4e0d\u53ea 7 \u500b\u984f\u8272 (\u7570\u4e16\u754c\u6709\u53ef\u80fd\u6709 87 \u8272\u7684\u5f69\u8679) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[25],"tags":[14,20,8,11,9],"class_list":["post-1205","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-map","tag-20","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=1205"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1205\/revisions"}],"predecessor-version":[{"id":1206,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1205\/revisions\/1206"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}