D. Denouncing Mafia

Codeforces
IDCF10234D
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
The complete problemset is available on http://maratona.ime.usp.br/primfase19/provas/competicao/maratona_en.pdf [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be an even integer denoting the number of digits in the ticket. Let $ s \in \{0,1,\dots,9,\texttt{?}\}^n $ be the ticket string, where $ \texttt{?} $ denotes an erased digit. Let $ q $ be the number of `?` characters in $ s $, with $ q $ even. Partition $ s $ into two halves: - Left half $ L = s[1:\frac{n}{2}] $, right half $ R = s[\frac{n}{2}+1:n] $. Let $ S_L $ be the sum of known digits in $ L $, $ S_R $ the sum of known digits in $ R $. Let $ q_L $ be the number of `?` in $ L $, $ q_R $ the number of `?` in $ R $, so $ q_L + q_R = q $. **Constraints** 1. $ 2 \le n \le 2 \cdot 10^5 $ 2. $ q $ is even, $ 0 \le q \le n $ 3. Players alternate turns, Monocarp first. Each turn, a player replaces one `?` with a digit in $ \{0,1,\dots,9\} $. 4. Game ends when all `?` are filled. **Objective** Determine the winner under optimal play: - Bicarp wins if $ S_L + \text{sum of digits added to } L = S_R + \text{sum of digits added to } R $. - Monocarp wins otherwise. Let $ d = S_R - S_L $ be the initial difference. Let $ x $ be the total sum added to $ L $, $ y $ the total sum added to $ R $. Bicarp wins iff $ x - y = d $. Total moves: $ q $, Monocarp makes $ \frac{q}{2} $ moves, Bicarp makes $ \frac{q}{2} $ moves. Monocarp controls $ \frac{q_L + q_R}{2} $ moves total, but can choose any `?` position. Bicarp responds optimally. **Key Insight** The game reduces to: - Monocarp aims to prevent $ x - y = d $. - Bicarp aims to achieve $ x - y = d $. - Each player chooses a position (left or right) and assigns a digit 0–9. Define: - $ a = q_L $, $ b = q_R $, so $ a + b = q $. - Let $ m = \frac{q}{2} $: each player makes $ m $ moves. Monocarp can choose to play on left or right; Bicarp responds. Bicarp wins if and only if: $$ d = \frac{9}{2}(b - a) $$ and both players play optimally. **Final Condition** Bicarp wins if and only if: $$ S_R - S_L = \frac{9}{2}(q_L - q_R) $$ Otherwise, Monocarp wins.
API Response (JSON)
{
  "problem": {
    "name": "D. Denouncing Mafia",
    "description": {
      "content": "The complete problemset is available on http://maratona.ime.usp.br/primfase19/provas/competicao/maratona_en.pdf ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10234D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The complete problemset is available on http://maratona.ime.usp.br/primfase19/provas/competicao/maratona_en.pdf\n\n[samples]...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be an even integer denoting the number of digits in the ticket.  \nLet $ s \\in \\{0,1,\\dots,9,\\texttt{?}\\}^n $ be the ticket string, where $ \\texttt{?} $ den...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments