|
47857 | 47857 | <ul class="md-nav__list"> |
47858 | 47858 |
|
47859 | 47859 | <li class="md-nav__item"> |
47860 | | - <a href="#solution-1" class="md-nav__link"> |
| 47860 | + <a href="#solution-1-case-analysis" class="md-nav__link"> |
47861 | 47861 | <span class="md-ellipsis"> |
47862 | | - Solution 1 |
| 47862 | + Solution 1: Case Analysis |
47863 | 47863 | </span> |
47864 | 47864 | </a> |
47865 | 47865 |
|
@@ -82198,7 +82198,18 @@ <h2 id="description">Description</h2> |
82198 | 82198 | <h2 id="solutions">Solutions</h2> |
82199 | 82199 | <!-- solution:start --> |
82200 | 82200 |
|
82201 | | -<h3 id="solution-1">Solution 1</h3> |
| 82201 | +<h3 id="solution-1-case-analysis">Solution 1: Case Analysis</h3> |
| 82202 | +<p>If the number of <code>'?'</code> is odd, Alice will definitely win because she can choose to replace the last <code>'?'</code> with any digit, making the sum of the first half different from the sum of the second half.</p> |
| 82203 | +<p>If the number of <code>'?'</code> is even, Alice will try to make the sums of the two halves different by placing $9$ in the half with the larger current sum and $0$ in the half with the smaller current sum. Bob, on the other hand, will try to make the sums equal by placing a digit in the other half that matches the digit Alice placed.</p> |
| 82204 | +<p>As a result, all remaining even-numbered <code>'?'</code> will be concentrated in one half. Suppose the current difference between the sums of the two halves is $d$.</p> |
| 82205 | +<p>Let's consider the case where there are two remaining <code>'?'</code> and the difference is $x$:</p> |
| 82206 | +<ul> |
| 82207 | +<li>If $x \lt 9$, Alice will definitely win because she can replace one of the <code>'?'</code> with $9$, making the sums of the two halves different.</li> |
| 82208 | +<li>If $x \gt 9$, Alice will definitely win because she can replace one of the <code>'?'</code> with $0$, making the sums of the two halves different.</li> |
| 82209 | +<li>If $x = 9$, Bob will definitely win. Suppose Alice replaces a digit with $a$, then Bob can replace the other <code>'?'</code> with $9 - a$, making the sums of the two halves equal.</li> |
| 82210 | +</ul> |
| 82211 | +<p>Therefore, if the difference between the sums of the two halves is $d = \frac{9 \times \textit{cnt}}{2}$, where $\textit{cnt}$ is the number of remaining <code>'?'</code>, Bob will definitely win; otherwise, Alice will definitely win.</p> |
| 82212 | +<p>The time complexity is $O(n)$, where $n$ is the length of the string. The space complexity is $O(1)$.</p> |
82202 | 82213 | <div class="tabbed-set tabbed-alternate" data-tabs="1:5"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label></div> |
82203 | 82214 | <div class="tabbed-content"> |
82204 | 82215 | <div class="tabbed-block"> |
|
0 commit comments