No.3682 きあいのハチマキ
タグ : / 解いたユーザー数 72
作問者 :
Andrew8128
/ テスター :
drken1215
ゆにたりー卿
lp_ql
yimiya(いみや)
よには
👑
leaf_1415
triangle_coder
👑 This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
Cyan-rated Iwai Seijin and Green-rated Iwai Seijin are having a battle.
Cyan-rated Iwai Seijin has initial HP $H_C$, attack power $A_C$, and speed $S_C$.
Green-rated Iwai Seijin has initial HP $H_G$, attack power $A_G$, and speed $S_G$.
The battle proceeds as follows.
-
- If the speeds of Cyan-rated Iwai Seijin and Green-rated Iwai Seijin differ, the Iwai Seijin with the greater speed attacks (the other Iwai Seijin receives the attack).
- If the speeds of Cyan-rated Iwai Seijin and Green-rated Iwai Seijin are the same, Cyan-rated Iwai Seijin attacks with probability $\frac{1}{2}$, and Green-rated Iwai Seijin attacks with probability $\frac{1}{2}$.
- The Iwai Seijin who did not attack in step 1. attacks.
- Return to step 1.
When an attack is made, the HP of the Iwai Seijin receiving the attack decreases by the attack power of the Iwai Seijin making the attack.
Both Iwai Seijin hold a Focus Band, so when an attack would bring their HP to $0$ or below, with probability $\frac{1}{10}$ they endure it and remain with $1$ HP.Note that when they receive an attack while at $1$ HP, they also endure it and remain with $1$ HP with probability $\frac{1}{10}$.
More formally, when an Iwai Seijin with current HP $H$ receives an attack from an Iwai Seijin with attack power $A$:- If $H \gt A$, the new HP of the Iwai Seijin receiving the attack becomes $H - A$.
- If $H \leq A$, the new HP of the Iwai Seijin receiving the attack becomes $1$ with probability $\frac{1}{10}$, and $H - A$ with probability $\frac{9}{10}$.
The battle ends immediately as soon as either one's HP becomes $0$ or below, and the Iwai Seijin whose HP became $0$ or below loses. (The Iwai Seijin who did not lose wins.)
Find the probability that Cyan-rated Iwai Seijin has won when the battle ends, modulo $\mathrm{mod}\ 998244353$.
What is a probability $\mathrm{mod}\ 998244353$?
It can be proved that the desired probability is always a rational number. It can also be proved that under the constraints of this problem, when the value is expressed as an irreducible fraction $\frac{P}{Q}$, we have $Q \not\equiv 0\ (\mathrm{mod}\ 998244353)$. Therefore, there is a unique integer $R$ satisfying $ R \times Q \equiv P\ (\mathrm{mod}\ 998244353), 0 \leq R \lt 998244353$. Report this $R$.You are given $T$ test cases; find the answer for each of them.
Constraints
All input values are integers.
$1 \leq T \leq 2 \times 10^{4}$
$1 \leq H_C, A_C, S_C, H_G, A_G, S_G \leq 10^{18}$
Input
The input is given from standard input in the following format, where $\mathrm{case}_i$ denotes the $i$-th test case.
$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$
Each test case is given in the following format.
$H_C\ A_C\ S_C\ H_G\ A_G\ S_G$
Output
Output $T$ lines.
On the $i$-th line, output the answer to the $i$-th test case.
Sample
Sample 1
Input
5 2 1 1 1 1 2 1000 100 10 1000 100 10 31 4 1 5 9 2 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 2408866010 1000000000000000000 819558960 819558960 819558960 1 1 1
Output
725995894 499122177 971019508 0 20260516
In the first test case, the probability that Cyan-rated Iwai Seijin wins is $\frac{10}{11}$. In the second test case, the probability that Cyan-rated Iwai Seijin wins is $\frac{1}{2}$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。