#P9217. 「TAOI-1」拼凑的断音

「TAOI-1」拼凑的断音

Background

flick tap flick tap 面を滑って
swipe tap swipe tap 「A.R→T」
flick tap flick tap 開いて叩いて
swipe swipe swipe swipe …もう嫌だな
ズルズル 糸が呟く

Problem Description

There are nn notes in front of you, and their pleasantness is described by the sequence {an}\{a_n\}.

Now there are nn types of magic. The ii-th type of magic will increase aia_i by ss (s>0s \gt 0). The success probability of each type of magic is pq\dfrac{p}{q}, and they are independent of each other.

Find the expected value of the pleasantness of the most pleasant note in the end (that is, maxi=1nai\max\limits_{i=1}^n a_i) after applying the magic.

This problem has a Special Judge. You may output the answer in two different ways. See [Output Format] for details.

Input Format

The first line contains four integers n,p,q,sn, p, q, s.

The second line contains nn integers aia_i, separated by spaces.

Output Format

This problem has two different output formats.

  • The first output format:

    Output 1 on the first line.

    Then, output the required expectation on the second line. It should be a real number.

    If your answer differs from the standard answer by at most 10410^{-4}, it will be judged correct. However, due to well-known floating-point errors, the judging result is not guaranteed to be 100% accurate. If you are sure your program is correct but cannot get AC, you may try the second output format.

  • The second output format:

    Output 2 on the first line.

    Next, if the expectation you computed is mn\dfrac{m}{n} (clearly the expectation is a rational number), then output on the second line its value modulo 998244353998244353, i.e. an integer xx in [0,998244353)[0, 998244353) such that xnm(mod998244353)xn \equiv m \pmod {998244353}.

3 1 3 2
1 2 3
1
3.888889
3 1 3 2
1 2 3
2
554580200

Hint

Constraints

This problem uses bundled testdata.

  • Subtask 1 (20 points): n15n \leq 15.
  • Subtask 2 (15 points): Guaranteed that i[1,n),aiai+1\forall i \in [1, n), a_i \leq a_{i+1}, and anan1+sa_n \geq a_{n-1}+s.
  • Subtask 3 (15 points): Guaranteed that i,j[1,n],ai=aj\forall i,j\in[1,n], a_i = a_j.
  • Subtask 4 (50 points): No special constraints.

For all testdata, 1n1051 \leq n \leq 10^5, 1p<q1071 \leq p \lt q \leq 10^7, 1ai,s1071 \leq a_i,s \leq 10^7.

Sample Explanation

Note that the two sample inputs are the same; the only difference is the output format.

Below are all possible cases of whether each magic succeeds, along with the corresponding maximum value, its probability, and its contribution to the expectation:

Magic Case Maximum Pleasantness Probability Contribution to Expectation
1,2,3{\color{black}1},{\color{black}2},{\color{black}3} 33 827\dfrac{8}{27} 89\dfrac{8}{9}
3,2,3{\color{red}3},{\color{black}2},{\color{black}3} 427\dfrac{4}{27} 49\dfrac{4}{9}
1,4,3{\color{black}1},{\color{red}4},{\color{black}3} 44 1627\dfrac{16}{27}
1,2,5{\color{black}1},{\color{black}2},{\color{red}5} 55 2027\dfrac{20}{27}
3,4,3{\color{red}3},{\color{red}4},{\color{black}3} 44 227\dfrac{2}{27} 827\dfrac{8}{27}
3,2,5{\color{red}3},{\color{black}2},{\color{red}5} 55 1027\dfrac{10}{27}
1,4,5{\color{black}1},{\color{red}4},{\color{red}5}
3,4,5{\color{red}3},{\color{red}4},{\color{red}5} 127\dfrac{1}{27} 527\dfrac{5}{27}

Therefore, the final answer is 359\dfrac{35}{9}.

  • Using the first output format, its value is approximately 3.8888893.888889.
  • Using the second output format, you can find that 554580200×935(mod998244353)554580200 \times 9 \equiv 35 \pmod {998244353}.

Translated by ChatGPT 5