No.1173 Endangered Species
Problem Statement
Each individual of a certain organism is assigned, at the moment of its birth, an integer value among $1, \dots, N$ as its individual value. Also, exactly $1$ day after its birth, it gives birth to $0$ or more individuals, and at the same time it disappears.
The individual value of a newborn individual and the number of individuals that $1$ individual gives birth to are determined probabilistically as follows, independently of other individuals:
- the probability that the individual value of a newborn individual is $i\ (=1,\dots,N)$ is $p_i$,
- the probability that the number of individuals born from $1$ individual with individual value $i$ is $k\ (=0,1,\dots)$ is $(1-q_i) q_i^k$.
Now, $A_1,\dots,A_N$ individuals with individual values $1,\dots,N$, respectively, have just been born. No other individuals exist. Find the probability $P$ that the organism is extinct after $10^{10^{100}}$ days, that is, that the number of individuals is $0$.
Since $P$ may be very small, output the value of its natural logarithm $\log P$. Under the constraints of this problem, it can be shown that $P > 0$.
Input
The input is given in the following format:
$N$ $p_1 \quad p_2 \quad \cdots \quad p_N$ $q_1 \quad q_2 \quad \cdots \quad q_N$ $A_1 \quad A_2 \quad \cdots \quad A_N$
- $N,\ A_1,\dots,A_N$ are integers
- $p_1,\dots,p_N,\ q_1,\dots,q_N$ are decimals with $6$ digits after the decimal point (padded with $0$ so as to have $6$ digits)
- $1 \leq N \leq 10^5$
- $0 < p_i \leq 1 \quad (1 \leq i \leq N)$
- $\sum_{i=1}^N p_i = 1$
- $\color{red}{0.6 \leq q_i \leq 0.9} \quad (1 \leq i \leq N)$
- $0 \leq A_i \leq 10^4 \quad (1 \leq i \leq N)$
Note: The somewhat unnatural-looking constraint on $q_i$ is there so that solutions using the double type can be accepted without much concern about numerical errors.
Output
For the probability $P$ that the organism is extinct after $10^{10^{100}}$ days, output the value of the natural logarithm $\log P$. Output a newline at the end.
Your answer is considered correct if its absolute or relative error from the expected answer is at most $10^{-5}$.
Sample
Sample 1
Input
1 1.000000 0.600000 1
Output
-0.4054651081
Every individual gives birth to $k$ individuals with probability $(2/5) \times (3/5)^k$.
The calculation is omitted, but the extinction probability is $P = 2/3$. Therefore, output an approximation of $\log (2/3) = -0.4054651081\dots$.
Sample 2
Input
2 0.900000 0.100000 0.900000 0.900000 0 0
Output
0
The organism may be extinct from the very beginning.
Sample 3
Input
6 0.332343 0.068862 0.076451 0.120693 0.263170 0.138481 0.839426 0.728493 0.810372 0.839476 0.827081 0.890719 7481 5029 9181 6723 8291 9836
Output
-75700.00551
$P \simeq 10^{-32876}$, which is very small. This is not an endangered species.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
opt