85 lines
14 KiB
JSON
85 lines
14 KiB
JSON
{
|
|
"category_name": "main",
|
|
"contest_code": "START209D",
|
|
"contest_name": "Starters 209 (Rated)",
|
|
"status": "success",
|
|
"submit_error": "You need to login to submit.",
|
|
"is_verified": false,
|
|
"problem_code": "P5209",
|
|
"contest_category": "9",
|
|
"problem_name": "Binary Love",
|
|
"intended_contest_code": "START209",
|
|
"body": "This is an example problem statement in markdown, and a mini guide on writing statements. Please make sure to remove everything here before publishing your problem.\n\n- Codechef uses markdown for its problem statements. Markdown syntax can be found [here](https:\/\/github.com\/showdownjs\/showdown\/wiki\/Showdown's-Markdown-syntax). Note the `[text](link)` syntax to insert a hyperlink.\n- Codechef also uses $\\LaTeX$ to render mathematical expressions, and you are advised to make liberal use of it to make your statement look good.\n- Text can be made **bold** or *italicized*.\n- **Do not** use HTML tags (p, ul, li, pre, br, ...) in the statement.\n- To insert an image, first upload it to an online hosting service (for an official contest, ask a Codechef admin to do this for you \u2014 this is important) and then use the following syntax: ``.\n- If your problem doesn't contain subtasks, ensure that the Subtasks section below is disabled and **all content is deleted from it**.\n\nIf you face any issues, either contact a Codechef admin directly or send us an email at help@codechef.com.\n\nBelow is an example problem statement that uses some of the above-mentioned features.\n\n---------\n\nChef has a simple undirected graph $G$ with $N$ vertices and $M$ edges. A [subgraph](https:\/\/mathworld.wolfram.com\/Subgraph.html) $H$ of $G$ is called *good* if:\n- $H$ is connected\n- $H$ contains all $N$ vertices of $G$\n- There is a unique path between any two vertices in $H$, using only edges in $H$\n\nCount the number of *good* subgraphs of $G$. Since this number might be large, report it modulo $10^9 + 7$.\n\nIn other news, here's a completely unrelated image:\n\n.\n\n\n<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.<\/div><\/aside>",
|
|
"problemComponents": {
|
|
"constraints": "- $1 \\leq T \\leq 2\\cdot 10^5$\n- $1 \\leq N \\leq 2\\cdot 10^5$\n- $S_i \\in \\{0, 1\\}$\n- The sum of $N$ over all test cases won't exceed $2\\cdot10^5$.",
|
|
"constraintsState": true,
|
|
"subtasks": "- **Subtask 1 (10 points):** $1 \\leq M \\leq 10$\n- **Subtask 2 (20 points):** The sum of $N$ across all test cases won't exceed $20$.\n- **Subtask 3 (70 points):** No further constraints.",
|
|
"subtasksState": false,
|
|
"statement": "Alice and Bob are playing a game on a binary string $S$ of length $N$.\n\nAlice wants to make the number of substrings ``01`` and ``10`` equal, and both counts must be non-zero. \nFormally, let $c_{01}$ denote the number of indices $i$ ($1 \\le i \\lt N$) such that $S_i = 0$ and $S_{i+1} = 1$, and similarly let $c_{10}$ denote the number of indices $i$ ($1 \\le i \\lt N$) such that $S_i = 1$ and $S_{i+1} = 0$. \nAlice would like for $c_{01} = c_{10}$ and $c_{01} \\gt 0$ to both hold.\n\nBob, on the other hand, wants to prevent Alice from achieving this condition.\n\nThe players take turns alternately, with Alice going first. \nIn each turn, the current player can remove exactly one character from either the beginning or the end of the string.\n\nThe game ends immediately when the string becomes empty or when Alice's desired condition ($c_{01} = c_{10} \\gt 0$) is satisfied. \n\nIf Alice can make the number of ``01`` and ``10`` substrings equal (and both non-zero), she wins. \nOtherwise, if Bob can prevent this condition until the string becomes empty, Bob wins. \nIn particular, if the initial string satisfies the required condition, Alice wins immediately, without even having to make a move.\n\nDetermine the winner of the game if both players play optimally.",
|
|
"inputFormat": "- The first line of input contains a single integer $T$, denoting the number of test cases.\n- Each test case consists of two lines of input:\n - The first line contains a single integer $N$ \u2014 the length of the binary string.\n - The second line contains the binary string $S$ of length $N$, consisting only of characters `0` and `1`.\n",
|
|
"inputFormatState": true,
|
|
"outputFormat": "For each test case, output a single string \u2014 ``Alice`` if Alice wins the game, or ``Bob`` if Bob wins the game.\n\nYou may print each character of the string in uppercase or lowercase (for example, the strings `BOB`, `bOb`, `bob`, and `boB` will all be treated as identical).",
|
|
"outputFormatState": true,
|
|
"sampleTestCases": [
|
|
{
|
|
"id": "1",
|
|
"input": "4\n3\n000\n3\n010\n4\n0001\n4\n0101",
|
|
"output": "Bob\nAlice\nBob\nAlice",
|
|
"explanation": "**Test case $1$:** We have $c_{01} = c_{10} = 0$ for the initial string. \nNo matter what the players do in terms of deleting characters, this won't change. \nAlice wants $c_{01} \\gt 0$, so she cannot win here.\n\n**Test case $2$:** We have $c_{01} = c_{10} = 1$ initially. \nAlice's condition is already satisfied, so she wins immediately.\n\n**Test case $4$:** We have $S = 0101$, for which $c_{01} = 2$ and $c_{10} = 1$. \nAlice must make a move; she can delete the last character to make $S = 010$ which as seen earlier satisfies Alice's condition; so Alice wins.",
|
|
"isDeleted": false
|
|
}
|
|
]
|
|
},
|
|
"gumlet_video_url": "",
|
|
"video_editorial_url": "https:\/\/youtu.be\/CcF-1sSHfaw?si=eQ_hKVflOJ63dzZJ",
|
|
"text_editorial_body": "<h1><a name=\"problem-link-1\" class=\"anchor\" href=\"#problem-link-1\"><\/a>PROBLEM LINK:<\/h1>\n<p><a href=\"https:\/\/www.codechef.com\/problems\/P5209\">Practice<\/a><br>\n<a href=\"https:\/\/www.codechef.com\/START209A\/problems\/P5209\">Contest: Division 1<\/a><br>\n<a href=\"https:\/\/www.codechef.com\/START209B\/problems\/P5209\">Contest: Division 2<\/a><br>\n<a href=\"https:\/\/www.codechef.com\/START209C\/problems\/P5209\">Contest: Division 3<\/a><br>\n<a href=\"https:\/\/www.codechef.com\/START209D\/problems\/P5209\">Contest: Division 4<\/a><\/p>\n<p><em><strong>Author:<\/strong><\/em> <a href=\"https:\/\/www.codechef.com\/users\/pols_agyi_pols\">pols_agyi_pols<\/a><br>\n<em><strong>Tester:<\/strong><\/em> <a href=\"https:\/\/www.codechef.com\/users\/kingmessi\">kingmessi<\/a><br>\n<em><strong>Editorialist:<\/strong><\/em> <a href=\"https:\/\/www.codechef.com\/users\/iceknight1093\">iceknight1093<\/a><\/p>\n<h1><a name=\"difficulty-2\" class=\"anchor\" href=\"#difficulty-2\"><\/a>DIFFICULTY:<\/h1>\n<p>Simple<\/p>\n<h1><a name=\"prerequisites-3\" class=\"anchor\" href=\"#prerequisites-3\"><\/a>PREREQUISITES:<\/h1>\n<p>None<\/p>\n<h1><a name=\"problem-4\" class=\"anchor\" href=\"#problem-4\"><\/a>PROBLEM:<\/h1>\n<p>Alice and Bob play a game on a binary string <span class=\"math\">S<\/span>.<br>\nOn their turn, a player must remove one character from either the front or the back of <span class=\"math\">S<\/span>.<\/p>\n<p>Alice\u2019s goal is to make <span class=\"math\">S<\/span> a non-empty string with an equal count of <code>01<\/code> and <code>10<\/code> substrings.<br>\nBob\u2019s goal is to make the string empty without the above ever happening.<\/p>\n<p>With optimal play, who wins?<\/p>\n<h1><a name=\"explanation-5\" class=\"anchor\" href=\"#explanation-5\"><\/a>EXPLANATION:<\/h1>\n<p>Let\u2019s understand what it means for a string to have an equal number of <code>01<\/code> and <code>10<\/code> substrings.<\/p>\n<p>Suppose <span class=\"math\">S_1 = 0<\/span>.<br>\nThen, as we go left to right, the following can be seen:<\/p>\n<ul>\n<li>We\u2019ll see several zeros; which don\u2019t create any <code>01<\/code> or <code>10<\/code> substrings.<\/li>\n<li>Then, we\u2019ll see a <span class=\"math\">1<\/span> for the first time.<br>\nThis will create a <code>01<\/code> substring.<\/li>\n<li>After that, there will be several ones; but again no <code>01<\/code> or <code>10<\/code> substrings will be present while this happens.<\/li>\n<li>Next, we\u2019ll encounter a <span class=\"math\">0<\/span>, which creates a <code>10<\/code> substring.<br>\nAfter this, again no <code>01<\/code> or <code>10<\/code> substrings will be created, till we reach another <span class=\"math\">1<\/span>, and so on.<\/li>\n<\/ul>\n<p>More generally, as we move left to right, a <code>10<\/code> or <code>01<\/code> substring will be created exactly each time we \u201cchange\u201d characters.<br>\nFurther, changing from <span class=\"math\">0<\/span> to <span class=\"math\">1<\/span> creates an occurrence of <code>01<\/code>, and changing from <span class=\"math\">1<\/span> to <span class=\"math\">0<\/span> creates an occurrence of <span class=\"math\">10<\/span>.<\/p>\n<p>Because of this, observe that we\u2019ll actually alternate between seeing a <code>01<\/code> and a <code>10<\/code>.<br>\nThis means, in the end, the counts of <code>01<\/code> and <code>10<\/code> will either be equal, or they will differ by <span class=\"math\">1<\/span>.<\/p>\n<hr>\n<p>Let\u2019s use this observation to solve the problem.<\/p>\n<p>Alice wants the counts of <code>01<\/code> and <code>10<\/code> to be equal and positive.<br>\nLet <span class=\"math\">c_{01}<\/span> and <span class=\"math\">c_{10}<\/span> be the counts of substrings <code>01<\/code> and <code>10<\/code>, respectively.<br>\nObserve that if a player deletes the leftmost character <span class=\"math\">S_1<\/span>,<\/p>\n<ul>\n<li>If <span class=\"math\">S_1 = S_2<\/span>, then both <span class=\"math\">c_{01}<\/span> and <span class=\"math\">c_{10}<\/span> don\u2019t change.<\/li>\n<li>Otherwise, the count corresponding to the substring <span class=\"math\">S_1S_2<\/span> reduces by <span class=\"math\">1<\/span>.<\/li>\n<\/ul>\n<p>Similarly, if <span class=\"math\">S_N<\/span> is deleted, either both counts don\u2019t change, or exactly one count reduces by <span class=\"math\">1<\/span> (depending on how <span class=\"math\">S_N<\/span> compares to <span class=\"math\">S_{N-1}<\/span>.<\/p>\n<p>In particular, if <span class=\"math\">c_{01} = 0<\/span> or <span class=\"math\">c_{10} = 0<\/span> initially, it\u2019s impossible for Alice to achieve her goal of making both be <span class=\"math\">\\ge 1<\/span>, since deletion cannot increase counts.<\/p>\n<p>That leaves us with the case of <span class=\"math\">c_{01} \\ge 1<\/span> and <span class=\"math\">c_{10} \\ge 1<\/span>.<br>\nHere, Alice will always win, because:<\/p>\n<ul>\n<li>If <span class=\"math\">c_{01} = c_{10}<\/span> initially, Alice wins without even having to make a move.<\/li>\n<li>If not, then the counts must differ by <span class=\"math\">1<\/span>.<br>\nSuppose <span class=\"math\">c_{01} = c_{10} + 1<\/span>.<br>\nAs Alice and Bob delete characters, eventually a point will be reached where either <span class=\"math\">c_{01}<\/span> or <span class=\"math\">c_{10}<\/span> must decrease by <span class=\"math\">1<\/span>.<br>\nHowever, if <span class=\"math\">c_{10}<\/span> decreases by <span class=\"math\">1<\/span>, the difference between it and <span class=\"math\">c_{01}<\/span> will equal <span class=\"math\">2<\/span>; which is impossible.<br>\nSo, <span class=\"math\">c_{01}<\/span> must decrease by <span class=\"math\">1<\/span> instead; and now the counts are equal.<\/li>\n<\/ul>\n<p>This gives us a simple solution: compute the initial counts <span class=\"math\">c_{01}<\/span> and <span class=\"math\">c_{10}<\/span>, and check if they\u2019re both positive or not.<\/p>\n<h1><a name=\"time-complexity-6\" class=\"anchor\" href=\"#time-complexity-6\"><\/a>TIME COMPLEXITY:<\/h1>\n<p><span class=\"math\">\\mathcal{O}(N)<\/span> per testcase.<\/p>\n<h1><a name=\"code-7\" class=\"anchor\" href=\"#code-7\"><\/a>CODE:<\/h1>\n<details>\n<summary>\nEditorialist's code (PyPy3)<\/summary>\n<pre><code class=\"lang-python\">for _ in range(int(input())):\n n = int(input())\n s = list(input())\n t = sorted(s)\n \n if s == t or s == t[::-1]: print('Bob')\n else: print('Alice')\n<\/code><\/pre>\n<\/details>",
|
|
"text_editorial_is_markdown": 0,
|
|
"text_editorial_topic_id": 124414,
|
|
"languages_supported": "CPP20, PYTH 3, C, JAVA, PYP3, CS2, NODEJS, GO, TS, PHP, kotlin, rust, R",
|
|
"max_timelimit": "1",
|
|
"source_sizelimit": "50000",
|
|
"problem_author": "archit_adm",
|
|
"problem_display_authors": ["archit_adm"],
|
|
"problem_display_authors_html_handle": "<div class=\"multiple-usernames-container\"><a href='\/users\/archit_adm'>archit_adm<\/a><\/div>",
|
|
"problem_tester": null,
|
|
"problem_testers_usernames": ["kingmessi"],
|
|
"problem_tester_html_handle": "<div class=\"multiple-usernames-container\"><a href='\/users\/kingmessi'><span \n class='rating' \n style='display: inline-block; \n font-size: 10px; \n background: #D0011B;\n padding: 0 3px; \n line-height: 1.3; \n color: white;\n margin-right: 2px;'>7★<\/span><span class='m-username--link'>kingmessi<\/span><\/a><\/div>",
|
|
"problem_editorialist": "iceknight1093",
|
|
"date_added": "20-10-2025",
|
|
"ready_for_debug": false,
|
|
"problem_stats": {
|
|
"accuracy": 34.630000000000003,
|
|
"successful_submissions": "3434",
|
|
"total_submissions": "11315"
|
|
},
|
|
"user_tags": ["archit_adm", "simple", "start209"],
|
|
"computed_tags": [],
|
|
"difficulty_rating": "1536",
|
|
"best_tag": "",
|
|
"editorial_url": "",
|
|
"time": {
|
|
"view_start_date": 1761143406,
|
|
"submit_start_date": 1761143406,
|
|
"visible_start_date": 1761150606,
|
|
"end_date": 1761150606,
|
|
"current": 1761365590,
|
|
"practice_submission_allowed": false
|
|
},
|
|
"user": { "username": null, "access": "default", "isPremiumUser": false },
|
|
"bookmark_status": false,
|
|
"contest_problem_status": "unattempted",
|
|
"problem_status": "unattempted",
|
|
"is_direct_submittable": false,
|
|
"problemDiscussURL": "https:\/\/discuss.codechef.com\/search?q=P5209",
|
|
"is_a_practice_or_college_contest": false,
|
|
"votes_data": {
|
|
"SolutionVoteData": { "upvote_count": 0, "user_vote": 0 },
|
|
"HintsVoteData": { "upvote_count": 0, "user_vote": 0 },
|
|
"ProblemStatementVoteData": { "upvote_count": 23, "user_vote": 0 },
|
|
"DoubtSupportVoteData": { "upvote_count": 0, "user_vote": 0 }
|
|
},
|
|
"is_proctored": false,
|
|
"is_user_verified_for_proctoring": false,
|
|
"visitedContests": [],
|
|
"isSupportedByJudge": true
|
|
}
|