P1654 OSU!
Background
Original "Product Sorting", see P2577.
Description
osu is a popular casual game.
We can simplify and adapt its rules as follows:
There are $n$ operations. Each operation is either a success or a failure, where success is denoted by $1$ and failure by $0$. The $n$ operations form a binary string of length $n$. In this string, every maximal run of $X$ consecutive $1$'s contributes $X^3$ points to the score (i.e., these $X$ ones must not be contained within a longer run of consecutive $1$'s; see the sample explanation).
Given $n$ and the success probability of each operation, output the expected score, rounded to 1 decimal place.
Input Format
The first line contains a positive integer $n$, the number of operations.
Each of the next $n$ lines contains a real number in $[0, 1]$, denoting the success probability of each operation.
Output Format
Output a single real number, the answer, rounded to 1 decimal place.
Explanation/Hint
[Sample explanation]
$000$ has a score of $0$,$001$ has a score of $1$,$010$ has a score of $1$,$100$ has a score of $1$,$101$ has a score of $2$,$110$ has a score of $8$,$011$ has a score of $8$,$111$ has a score of $27$,the total is $48$, and the expectation is $\dfrac{48}8 = 6.0$.
Constraints: $n \leq 1 \times 10^5$.
Translated by ChatGPT 5