시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 512 MB | 5 | 3 | 2 | 50.000% |
You are a bettor. You have a given amount of money. You make bets of non-decreasing sizes, until you lose all your money or reach a specified threshold. You win in the former case and lose in the latter.
Formally, initially you have $x$ units of money and you have a counter $y$, which is equal to your last bet. It is initially equal to $0$. You repeatedly do the following:
What is the probability of winning if you bet optimally?
For those who like calculus, the probability of winning from a given position is the supremum of the set of probabilities of winning of all possible strategies.
Output the answer modulo 998244353. Formally, the actual answer is guaranteed to be an irreducible fraction $\frac{P}{Q}$ where Q is co-prime to 998244353. Output an integer $X$, such that $-2^{63} \leq X < 2^{63}$ and $XQ - P$ is divisible by 998244353.
Tests are generated randomly more or less, therefore if you do all calculations modulo 998244353 you won't encounter division of 0 by 0, unless you multiply both sides by a number divisible by 998244353 just for the sake of it.
Both $x$ and $p$ are given as irreducible fractions.
The only line of input contains four integers $a$, $b$, $d$ and $e$ ($1 \leq a, b, d, e \leq 10^6$).
$x$ is equal to $\frac{a}{b}$. $0 < x < 1$, i.e. $a < b$. $a$ and $b$ are co-prime.
$p$ is equal to $\frac{d}{e}$. $0 < p < \frac{1}{2}$, i.e. $d < \lceil \frac{e}{2} \rceil$. $d$ and $e$ are co-prime.
Output a single integer --- the answer to the problem modulo 998244353.
1 2 1 3
332748118
17 28 3 29
60518375
In the first example the best strategy is to simply bet all your $\frac{1}{2}$ money and win or lose instantly. The probability of winning is $p$ which is equal to $\frac{1}{3}$.
In this problem you can easily end up in a situation where you know a number $A$, such that for each real number $c$ except $A$, you have an argument that $c$ makes no sense as the answer to the problem. In that case $A$ is indeed the answer as the answer does always exist even if you don't have the strategy with probability of winning exactly $A$ (actually there may be no such strategy, example of a game where it is easier to understand is present later in the statement). However, for your convenience some definitions which may help you develop a better understanding of the problem are provided.
Limit of a sequence $f_n$ is an integer $F$, such that for all real $\varepsilon > 0$ there exists an integer $N$, such that for every $n > N, |f_n - F| < \varepsilon$. To put it more understandable way, $F$ is limit if elements of the sequence with a big enough indices become arbitrarily close to $F$. It can be proven that if the limit exists it is unique. If it does sequence $f_n$ is said to converge to $F$ and is called convergent. It can be shown that a sequence is convergent if and only if for all real $\varepsilon > 0$ there exists an integer $N$, such that for every $n_1, n_2 > N, |f_{n_1} - f_{n_2}| < \varepsilon$. In other words, a sequence converges if elements with big enough indices become arbitrarily close to each other. Examples:
Supremum, sometimes called the least upper bound, of a possibly infinite set of real numbers is the least real number greater or equal than all elements of the set. It can be proven that any non-empty set bounded from above has a supremum. Obviously the supremum is unique because there can not be multiple least numbers satisfying some property. One of them is always greater than another and is therefore not least. Examples:
Strategy is a definition of how you will play a game and which actions will you make under all possible circumstances. Examples:
Probability of winning for a particular strategy in a single player game is, surprisingly, the probability of that strategy leading to a win for the player. Examples:
Probability of winning a game is the supremum of the set of probabilities of winning of all possible strategies. Examples: