{"id":1412,"date":"2024-02-17T23:33:36","date_gmt":"2024-02-17T15:33:36","guid":{"rendered":"http:\/\/www.forillusion.com\/?p=1412"},"modified":"2025-02-14T11:39:10","modified_gmt":"2025-02-14T03:39:10","slug":"codeforces-round-925-div-3-solution","status":"publish","type":"post","link":"https:\/\/www.forillusion.com\/index.php\/codeforces-round-925-div-3-solution\/","title":{"rendered":"Codeforces Round 925 Div. 3 \u9898\u89e3"},"content":{"rendered":"\n<p><div class=\"has-toc have-toc\"><\/div><\/p>\n\n\n\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/codeforces.com\/contest\/1931\" target=\"_blank\" rel=\"nofollow\" >https:\/\/codeforces.com\/contest\/1931<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A. Recovering a Small String<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a800<\/p>\n\n\n\n<p>\u5c06a\u8bb0\u4e3a1\uff0cb\u8bb0\u4e3a2\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u7ed9\u51fa\u4e00\u4e2a3-78\u4e4b\u95f4\u7684\u4e00\u4e2a\u6570\uff0c\u6c42\u51fa\u4e00\u4e2a\u5b57\u5178\u5e8f\u6700\u5c0f\u76843\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u5f97\u8fd93\u4e2a\u5b57\u6bcd\u76f8\u52a0\u7b49\u4e8e\u7ed9\u5b9a\u7684\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int t,x,a,b,c;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI x;\n        F(i,1,26)\n            F(j,1,26)\n                F(k,1,26)\n                    if (i+j+k==x)\n                    {\n                        cout&lt;&lt;(char)(i-1+'a')&lt;&lt;(char)(j-1+'a')&lt;&lt;(char)(k-1+'a')&lt;&lt;endl;\n                        goto l;\n                    }\n        l:\n        x++;   \n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">B. Make Equal<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a800<\/p>\n\n\n\n<p>\u7ed9\u51fa\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u7684\u6bcf\u4e2a\u6570\u90fd\u53ef\u4ee5\u5206\u4e00\u90e8\u5206\u7ed9\u540e\u9762\u7684\u6570\uff0c\u95ee\u6700\u540e\u662f\u5426\u80fd\u591f\u8ba9\u6bcf\u4e2a\u6570\u90fd\u76f8\u7b49\u3002<\/p>\n\n\n\n<p>\u5148\u6c42\u51fa\u6570\u7ec4\u7684\u603b\u548c\u5e76\u6c42\u51fa\u5e73\u5747\u503c\uff0c\u4ece\u5934\u904d\u5386\u6570\u7ec4\uff0c\u540c\u65f6\u7528\u4e00\u4e2a\u53d8\u91cfx\u8bb0\u5f55\u5f53\u524d\u6570\u5b57\u52a0x\u540e\u6bd4\u5747\u503c\u591a\u51fa\u591a\u5c11\uff0c\u7136\u540e\u5c06x\u52a0\u4e0a\u5f53\u524d\u6570\u5b57\u5e76\u51cf\u53bb\u5747\u503c\uff0c\u5982\u679c\u56fe\u4e2d\u51fa\u73b0\u53d8\u91cfx\u52a0\u4e0a\u5f53\u524d\u6570\u5b57\u540e\u4f9d\u7136\u5c0f\u4e8e\u5747\u503c\uff0c\u5219\u6700\u540e\u65e0\u6cd5\u505a\u5230\u6bcf\u4e2a\u6570\u90fd\u76f8\u7b49\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int t,a&#91;200005],sum,n,avg,x,f;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        sum=x=0;\n        f=1;\n        CI n;\n        F(i,1,n)\n        {\n            CI a&#91;i];\n            sum+=a&#91;i];\n        }\n        avg=sum\/n;\n        F(i,1,n)\n        {\n            if (a&#91;i]+x&gt;=avg) x=a&#91;i]+x-avg;\n            else\n            {\n                f=0;\n                break;\n            }\n        }\n        if (f) CO \"YES\" L;\n        else CO \"NO\" L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">C. Make Equal Again<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a1000<\/p>\n\n\n\n<p>\u7ed9\u51fa\u4e00\u4e2a\u6570\u7ec4\uff0c\u4fee\u6539\u8fd9\u4e9b\u6570\u7ec4\u4e2d\u7684\u8fde\u7eed\u7684\u4e00\u4e32\u6570\uff0c\u4f7f\u5f97\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6570\u90fd\u76f8\u7b49\uff0c\u6c42\u51fa\u6700\u5c0f\u7684\u4fee\u6539\u6570\u91cf\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u5f97\u5230\u6700\u5c0f\u7684\u4fee\u6539\u6570\u91cf\uff0c\u53ef\u4ee5\u5206\u522b\u6c42\u51fa\u8fd9\u7ec4\u6570\u4e2d\u5f00\u5934\u548c\u7ed3\u5c3e\u76f8\u540c\u503c\u6709\u591a\u5c11\uff0c\u5982\u679c\u5f00\u5934\u548c\u7ed3\u5c3e\u76f8\u7b49\uff0c\u5219\u7528\u603b\u957f\u5ea6\u51cf\u53bb\u5f00\u5934\u548c\u7ed3\u5c3e\u76f8\u7b49\u503c\u7684\u957f\u5ea6\uff1b\u5426\u5219\u7528\u603b\u957f\u5ea6\u51cf\u53bb\u5f00\u5934\u548c\u7ed3\u5c3e\u4e2d\u8f83\u957f\u7684\u4e00\u4e2a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int t,n,a&#91;200005];\nint main()\n{\n    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI n;\n        F(i,1,n)\n            CI a&#91;i];\n        int l1=a&#91;1],l2=1,r1=a&#91;n],r2=1;\n        F(i,2,n)\n            if (a&#91;i]==l1) l2++;\n            else break;\n        FD(i,n-1,1)\n            if (a&#91;i]==r1) r2++;\n            else break;\n        if (l1==r1) CO max(0,n-l2-r2) L;\n        else CO min(n-l2,n-r2) L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">D. Divisible Pairs<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a1300<\/p>\n\n\n\n<p>\u627e\u5230\u9898\u76ee\u4e2d\u8981\u6c42\u7684\u6570\u7ec4\uff0c\u9700\u8981\u627e\u51fa\u5728\u524d\u9762\u4e2d\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u6570\u6ee1\u8db3(x-a%x)%x\uff0ca%y\u3002<\/p>\n\n\n\n<p>\u7528\u4e00\u4e2a\u5b57\u5178\uff0c\u952e\u4e3apair\uff0c\u5b58\u50a8\u7684\u662f(a%x,a%y\uff09\uff0c\u503c\u4e3a\u5f53\u524dpair\u51fa\u73b0\u7684\u6b21\u6570\u3002\u5982\u679c\u80fd\u627e\u5230((x-a%x)%x,a%y)\uff0c\u5219\u5c06ans\u52a0\u4e0a\u8be5\u952e\u5bf9\u5e94\u7684\u503c\u3002\u7136\u540e\u5c06\u5f53\u524d\u6570(a%x,a%y)\u52a0\u5165\u5230\u5b57\u5178\u4e2d\uff0c\u5982\u679c\u5df2\u5b58\u5728\uff0c\u5219\u5c06\u503c+1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">LL t,n,x,y,a,ans;\nint main()\n{\n    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        ans=0;\n        map&lt;pair&lt;LL,LL>,int> s;\n        CI n>>x>>y;\n        F(i,1,n)\n        {\n            CI a;\n            if (s.find(make_pair((x-a%x)%x,a%y))!=s.end()) ans+=s.find(make_pair((x-a%x)%x,a%y))->second;\n            if (s.find(make_pair(a%x,a%y))!=s.end()) s&#91;make_pair(a%x,a%y)]++;\n            else s.insert(make_pair(make_pair(a%x,a%y),1));\n        }\n        CO ans L;\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5\uff1ahttps:\/\/codeforces.com\/contest\/1931 A. Recovering a Small St &#8230;<\/p>","protected":false},"author":1,"featured_media":1416,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,35],"tags":[40,12,34,22,39],"class_list":["post-1412","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-3","category-35","tag-codeforces","tag-12","tag-34","tag-22","tag-39"],"_links":{"self":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/comments?post=1412"}],"version-history":[{"count":1,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1412\/revisions"}],"predecessor-version":[{"id":1726,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1412\/revisions\/1726"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media\/1416"}],"wp:attachment":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media?parent=1412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/categories?post=1412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/tags?post=1412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}