J. Jar of Water Game

Codeforces
IDCF10234J
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 the number of contests and friends. Let $ P, Q \in \mathbb{Z} $ such that $ p = \frac{P}{10^6} $, $ q = \frac{Q}{10^6} $, and $ r = 1 - p - q $. Let $ A = \{a_1, a_2, \dots, a_n\} \subset \mathbb{Z}^+ $ be the set of distinct desired T-shirt sizes. For each $ a_i \in A $, define the random variable $ X_i $ indicating whether a T-shirt of size $ a_i $ is received: $$ X_i = \begin{cases} 1 & \text{if at least one T-shirt of size } a_i \text{ is received}, \\ 0 & \text{otherwise}. \end{cases} $$ **Constraints** 1. $ 1 \le n \le 2 \cdot 10^5 $ 2. $ 0 \le P, Q \le 10^6 $, $ P + Q \le 10^6 $ 3. $ 1 \le a_i \le 10^9 $, all $ a_i $ distinct **Objective** Compute the expected number of friends who receive a T-shirt: $$ \mathbb{E}\left[\sum_{i=1}^n X_i\right] = \sum_{i=1}^n \mathbb{P}(X_i = 1) $$ For each $ a_i $, define the set of sizes that can produce a T-shirt of size $ a_i $: $$ S_i = \{a_i - 1, a_i, a_i + 1\} $$ Let $ C_j $ be the event that T-shirt size $ j $ is *requested* (i.e., $ j \in A $). Then the probability that size $ a_i $ is received is: $$ \mathbb{P}(X_i = 1) = 1 - \prod_{j \in S_i \cap A} \left(1 - \mathbb{P}(\text{size } j \text{ is chosen and yields } a_i)\right) $$ But more precisely: For each requested size $ a_i $, the T-shirt of size $ a_i $ can be obtained from: - Registering for $ a_i $: yields $ a_i $ with prob $ r $, $ a_i - 1 $ with prob $ p $, $ a_i + 1 $ with prob $ q $ - Registering for $ a_i - 1 $: yields $ a_i $ with prob $ q $ - Registering for $ a_i + 1 $: yields $ a_i $ with prob $ p $ Thus, the probability that **no** T-shirt of size $ a_i $ is received is: $$ \prod_{\substack{k \in A \\ k \in \{a_i - 1, a_i, a_i + 1\}}} \left(1 - \text{prob that registering for } k \text{ produces } a_i\right) $$ Let $ N_i = \{ k \in A \mid k \in \{a_i - 1, a_i, a_i + 1\} \} $ Then: $$ \mathbb{P}(X_i = 0) = \prod_{k \in N_i} \left(1 - \begin{cases} r & \text{if } k = a_i \\ q & \text{if } k = a_i - 1 \\ p & \text{if } k = a_i + 1 \end{cases}\right) $$ So: $$ \mathbb{P}(X_i = 1) = 1 - \prod_{k \in N_i} \left(1 - c_{k,i}\right) $$ where $ c_{k,i} = \begin{cases} r & k = a_i \\ q & k = a_i - 1 \\ p & k = a_i + 1 \end{cases} $ Finally, compute: $$ \mathbb{E} = \sum_{i=1}^n \left(1 - \prod_{k \in N_i} (1 - c_{k,i}) \right) $$ Output $ \mathbb{E} \mod 998244353 $, with all probabilities represented as modular inverses modulo $ 998244353 $.
API Response (JSON)
{
  "problem": {
    "name": "J. Jar of Water Game",
    "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": "CF10234J"
  },
  "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 the number of contests and friends.  \nLet $ P, Q \\in \\mathbb{Z} $ such that $ p = \\frac{P}{10^6} $, $ q = \\frac{Q}{10^6} $, and $ r = 1 - p - q $.  \nLet...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments