{"id":253,"date":"2026-08-01T22:32:44","date_gmt":"2026-08-01T14:32:44","guid":{"rendered":"https:\/\/huxiaole.cloud\/?p=253"},"modified":"2026-08-01T22:32:46","modified_gmt":"2026-08-01T14:32:46","slug":"b-%e4%ba%8c%e8%bf%9b%e5%88%b6%e4%b8%b2%e8%bd%ac%e5%9b%9e%e6%96%87%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/huxiaole.cloud\/index.php\/2026\/08\/01\/b-%e4%ba%8c%e8%bf%9b%e5%88%b6%e4%b8%b2%e8%bd%ac%e5%9b%9e%e6%96%87%e4%b8%b2\/","title":{"rendered":"B. \u4e8c\u8fdb\u5236\u4e32\u8f6c\u56de\u6587\u4e32"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u597d\u7684\uff0c\u660e\u767d\u4e86\u3002\u6211\u4e25\u683c\u4fdd\u6301\u4f60\u63d0\u4f9b\u7684\u6240\u6709\u5185\u5bb9\u4e0d\u53d8\uff0c\u53ea\u505a\u683c\u5f0f\u6574\u7406\uff08\u6807\u9898\u3001\u4ee3\u7801\u5757\u3001\u516c\u5f0f\u7b26\u53f7\u7b49\uff09\uff0c\u4e0d\u4fee\u6539\u4efb\u4f55\u6587\u5b57\u548c\u4ee3\u7801\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/codeforces.com\/gym\/106631\/problem\/B\">Codeforces \u9898\u76ee\u94fe\u63a5<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">B. \u4e8c\u8fdb\u5236\u4e32\u8f6c\u56de\u6587\u4e32<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u6b21\u6d4b\u8bd5\u65f6\u95f4\u9650\u5236\uff1a1 \u79d2<\/li>\n\n\n\n<li>\u5185\u5b58\u9650\u5236\uff1a256 MB<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u9898\u76ee\u63cf\u8ff0<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a $n$ \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 $b$\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u6784\u9020\u4e00\u4e2a\u957f\u5ea6\u4e3a $n$\u3001\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 $s$\uff0c\u4f7f\u5f97\u5bf9\u4e8e\u6bcf\u4e2a $i$\uff08$1 \\le i \\le n$\uff09\uff0c\u6ee1\u8db3\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u82e5 $b_i = 1$\uff0c\u5219 $s$ \u4e2d<strong>\u6240\u6709<\/strong>\u957f\u5ea6\u4e3a $i$ \u7684\u5b50\u4e32\u90fd\u662f\u56de\u6587\u4e32\uff1b<\/li>\n\n\n\n<li>\u82e5 $b_i = 0$\uff0c\u5219 $s$ \u4e2d<strong>\u81f3\u5c11\u6709\u4e00\u4e2a<\/strong>\u957f\u5ea6\u4e3a $i$ \u7684\u5b50\u4e32\u4e0d\u662f\u56de\u6587\u4e32\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u6ee1\u8db3\u6761\u4ef6\u7684<strong>\u5b57\u5178\u5e8f\u6700\u5c0f<\/strong>\u7684\u5b57\u7b26\u4e32 $s$\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b57\u7b26\u4e32\uff0c\u8f93\u51fa $-1$\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b50\u4e32\u5b9a\u4e49<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u7b26\u4e32 $x$ \u662f\u5b57\u7b26\u4e32 $y$ \u7684\u5b50\u4e32\uff0c\u5982\u679c $x$ \u53ef\u4ee5\u901a\u8fc7\u5220\u9664 $y$ \u5f00\u5934\u82e5\u5e72\uff08\u53ef\u80fd\u4e3a\u96f6\u6216\u5168\u90e8\uff09\u4e2a\u5b57\u7b26\u548c\u7ed3\u5c3e\u82e5\u5e72\uff08\u53ef\u80fd\u4e3a\u96f6\u6216\u5168\u90e8\uff09\u4e2a\u5b57\u7b26\u5f97\u5230\u3002\u4f8b\u5982\uff0c<code>bc<\/code>\u3001<code>abc<\/code> \u548c <code>d<\/code> \u90fd\u662f <code>abcd<\/code> \u7684\u5b50\u4e32\uff0c\u800c <code>ac<\/code> \u548c <code>ba<\/code> \u4e0d\u662f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u56de\u6587\u4e32\u5b9a\u4e49<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u56de\u6587\u4e32\uff0c\u5f53\u4e14\u4ec5\u5f53\u5b83\u4ece\u5de6\u5411\u53f3\u8bfb\u548c\u4ece\u53f3\u5411\u5de6\u8bfb\u5b8c\u5168\u76f8\u540c\uff0c\u5373\u5b57\u7b26\u4e32\u7684\u9006\u5e8f\u7b49\u4e8e\u539f\u4e32\u3002\u4f8b\u5982\uff0c<code>a<\/code>\u3001<code>aba<\/code> \u548c <code>abba<\/code> \u662f\u56de\u6587\u4e32\uff0c\u800c <code>ab<\/code> \u548c <code>abc<\/code> \u4e0d\u662f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u5178\u5e8f\u5b9a\u4e49<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u7b26\u4e32 $x$ \u6bd4\u5b57\u7b26\u4e32 $y$ \u5b57\u5178\u5e8f\u66f4\u5c0f\uff0c\u5f53\u4e14\u4ec5\u5f53\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>$x$ \u662f $y$ \u7684\u771f\u524d\u7f00\uff0c\u6216<\/li>\n\n\n\n<li>\u5b58\u5728\u67d0\u4e2a\u4f4d\u7f6e $i$\uff08$1 \\le i \\le \\min(|x|, |y|)$\uff09\uff0c\u4f7f\u5f97 $x_i &lt; y_i$\uff0c\u5e76\u4e14\u5bf9\u4e8e\u6240\u6709 $j &lt; i$\uff0c\u90fd\u6709 $x_j = y_j$\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u8f93\u5165\u683c\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u6574\u6570 $t$\uff08$1 \\le t \\le 10^4$\uff09\u2014\u2014 \u6d4b\u8bd5\u7528\u4f8b\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u7684\u7b2c\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u6574\u6570 $n$\uff08$1 \\le n \\le 3 \\times 10^5$\uff09\u2014\u2014 \u5b57\u7b26\u4e32 $b$ \u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e8c\u884c\u5305\u542b\u4e00\u4e2a\u957f\u5ea6\u4e3a $n$ \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 $b$\uff0c\u7531\u5b57\u7b26 <code>0<\/code> \u548c <code>1<\/code> \u7ec4\u6210\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fdd\u8bc1\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u7684 $n$ \u4e4b\u548c\u4e0d\u8d85\u8fc7 $3 \\times 10^5$\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u8f93\u51fa\u683c\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8f93\u51fa\u4e00\u884c\uff1a\u82e5\u5b58\u5728\u5408\u6cd5\u5b57\u7b26\u4e32\uff0c\u5219\u8f93\u51fa\u5b57\u5178\u5e8f\u6700\u5c0f\u7684 $s$\uff1b\u5426\u5219\u8f93\u51fa $-1$\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3\n2\n10\n3\n001\n4\n1111<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ab\n-1\naaaa<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\u8bf4\u660e<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff1a$b = 10$\u3002\u957f\u5ea6\u4e3a $1$ \u7684\u6240\u6709\u5b50\u4e32\u90fd\u5fc5\u987b\u662f\u56de\u6587\u4e32\uff08\u5355\u4e2a\u5b57\u7b26\u603b\u662f\u56de\u6587\uff09\uff0c\u800c\u957f\u5ea6\u4e3a $2$ \u7684\u552f\u4e00\u5b50\u4e32\u5fc5\u987b\u4e0d\u662f\u56de\u6587\u4e32\u3002\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u6ee1\u8db3\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u662f <code>ab<\/code>\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e8c\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff1a$b = 001$\u3002\u7531\u4e8e $b_1 = 0$\uff0c\u4f46\u5355\u4e2a\u5b57\u7b26\u603b\u662f\u56de\u6587\u4e32\uff0c\u56e0\u6b64\u4e0d\u5b58\u5728\u5408\u6cd5\u5b57\u7b26\u4e32\uff0c\u8f93\u51fa $-1$\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e09\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff1a$b = 1111$\u3002\u6240\u6709\u957f\u5ea6\u7684\u6240\u6709\u5b50\u4e32\u90fd\u5fc5\u987b\u662f\u56de\u6587\u4e32\u3002\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u6ee1\u8db3\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u662f <code>aaaa<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u601d\u8def<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u9053\u9898\u5f88\u5de7\u5999<br>\u6211\u4eec\u6ce8\u610f\u5230\u4e00\u4e2a\u5b57\u7b26\uff0c\u81ea\u5df1\u4e00\u5b9a\u662f\u56de\u6587\uff0c\u4e00\u5b9a\u7b26\u5408\u6761\u4ef6<br>\u800c\u4e14\u5982\u679c\u8fde\u7eed\u4e24\u4e2a\u5b57\u7b26\u76f8\u540c\uff0c\u90a3\u4e48\u8fde\u7eed\u4e24\u4e2a\u5b57\u7b26\u662f $aa$ \u7b2c\u4e8c\u4e2a\u548c\u7b2c\u4e09\u4e2a\u662f $aa$\uff0c\u7ed3\u679c\u5c31\u662f\u8fde\u7eed\u4e09\u4e2a\u5b57\u7b26\u4e5f\u76f8\u540c\uff0c\u4ee5\u6b64\u7c7b\u63a8\u6700\u540e\u4f1a\u5f97\u5230\u4e00\u4e2a\u5168\u662f $1$ \u7684\u60c5\u51b5\uff0c\u5bf9\u5e94\u4e0b\u5217\u60c5\u51b51<br>\u8fd9\u9053\u9898\u53ef\u4ee5\u901a\u8fc7\u5206\u7c7b\u8ba8\u8bba\u5f97\u51fa\u7b54\u6848<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>s = $111111$ \u4efb\u610f\u957f\u5ea6\u5b50\u4e32\u90fd\u76f8\u540c\uff0c\u6240\u4ee5\u6700\u7ec8\u7b54\u6848\u5c31\u662f $aaaaaaaa$<\/li>\n\n\n\n<li>s = $101010$ \u5076\u6570\u662f $0$\uff0c\u5947\u6570\u662f $1$\uff0c\u6240\u4ee5\u6700\u7ec8\u7b54\u6848\u662f $abababab$<\/li>\n\n\n\n<li>s = $100000$ \u6240\u4ee5\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u662f\u7b26\u5408\u7684\uff0c\u6240\u4ee5\u7b54\u6848\u662f $aaaaaaab$<\/li>\n\n\n\n<li>s = $100001$ \u6240\u4ee5\u4e00\u4e2a\u5b57\u7b26\u548c\u5168\u9009\u662f\u56de\u6587\uff0c\u6240\u4ee5\u7b54\u6848\u662f $aaaaabbaaaaa$ \u6216\u8005 $aaaaaaabaaaaaa$<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ee3\u7801<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Sunshine sunshine ladybugs awake,\n\/\/Clap your hooves and do a little shack.\n\n#include &lt;bits\/stdc++.h&gt;\n#define int long long\n#define endl \"\\n\"\n\nusing namespace std;\n\nusing PII = pair&lt;int, int&gt;;\nconst int MAXN = 300005;\nconst int mod = 998244353;\nconst int INF = 0x3f3f3f3f3f3f3f3f;\n\nint n;\nstring s;\n\n\/\/ \u60c5\u51b51: b \u5168\u4e3a '1'\nbool case1() {\n    string type1(n, '1');\n    if (s == type1) {\n        cout &lt;&lt; string(n, 'a') &lt;&lt; endl;\n        return true;\n    }\n    return false;\n}\n\n\/\/ \u60c5\u51b52: b \u4e3a \"1010...\"\uff08\u5076\u6570\u7d22\u5f15\u4e3a '1'\uff09\nbool case2() {\n    string type2(n, '0');\n    for (int i = 0; i &lt; n; i++) {\n        if (i % 2 == 0) {\n            type2&#91;i] = '1';\n        }\n    }\n    if (s == type2) {\n        for (int i = 0; i &lt; n; i++) {\n            cout &lt;&lt; (i % 2 == 0 ? 'a' : 'b');\n        }\n        cout &lt;&lt; endl;\n        return true;\n    }\n    return false;\n}\n\n\/\/ \u60c5\u51b53: b \u4e3a \"100...0\"\uff08\u4ec5\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e3a '1'\uff09\nbool case3() {\n    string type3 = string(n, '0');\n    type3&#91;0] = '1';\n    if (s == type3) {\n        for (int i = 0; i &lt; n - 1; i++) {\n            cout &lt;&lt; \"a\";\n        }\n        cout &lt;&lt; \"b\" &lt;&lt; endl;\n        return true;\n    }\n    return false;\n}\n\n\/\/ \u60c5\u51b54: b \u4e3a \"100...001\"\uff08\u9996\u5c3e\u4e3a '1'\uff0c\u4e2d\u95f4\u5168 '0'\uff09\nbool case4() {\n    string type4(n, '0');\n    type4&#91;0] = '1';\n    type4&#91;n - 1] = '1';\n    if (s == type4) {\n        string ans = string(n, 'a');\n        \/\/ \u5c06\u4e2d\u95f4\u4e24\u4e2a\u4f4d\u7f6e\u6539\u4e3a 'b'\uff0c\u4f7f\u5f97\u6574\u4e2a\u4e32\u4e0d\u662f\u56de\u6587\n        ans&#91;(n - 1) \/ 2] = 'b';\n        ans&#91;n \/ 2] = 'b';\n        cout &lt;&lt; ans &lt;&lt; endl;\n        return true;\n    }\n    return false;\n}\n\nvoid solve() {\n    cin &gt;&gt; n &gt;&gt; s;\n\n    if (case1()) return;\n    if (case2()) return;\n    if (case3()) return;\n    if (case4()) return;\n\n    cout &lt;&lt; \"-1\" &lt;&lt; endl;\n}\n\nsigned main() {\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    int t;\n    cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\u7684\uff0c\u660e\u767d\u4e86\u3002\u6211\u4e25\u683c\u4fdd\u6301\u4f60\u63d0\u4f9b\u7684\u6240\u6709\u5185\u5bb9\u4e0d\u53d8\uff0c\u53ea\u505a\u683c\u5f0f\u6574\u7406\uff08\u6807\u9898\u3001\u4ee3\u7801\u5757\u3001\u516c\u5f0f\u7b26\u53f7\u7b49\uff09\uff0c\u4e0d\u4fee\u6539\u4efb\u4f55\u6587\u5b57\u548c\u4ee3\u7801\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":214,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,11,10],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codeforces","category-11","category-10"],"_links":{"self":[{"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":1,"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions\/254"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/media\/214"}],"wp:attachment":[{"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huxiaole.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}