#P10141. [USACO24JAN] Merging Cells P
[USACO24JAN] Merging Cells P
Problem Description
**Note: The memory limit for this problem is 512MB, twice the default.**
Bessie is having fun playing a famous online game, where there are a bunch of cells of different labels and sizes. Cells get eaten by other cells until only one winner remains.
There are () cells in a row labeled from left to right, with initial sizes (). While there is more than one cell, a pair of adjacent cells is selected uniformly at random and merged into a single new cell according to the following rule:
If a cell with label and current size is merged with a cell with label and current size , the resulting cell has size and label equal to that of the larger cell, breaking ties by larger label. Formally, the label of the resulting cell is $\begin{cases} a & c_a > c_b \\ b & c_a < c_b \\ \max(a,b) & c_a = c_b \end{cases}.$
For each label in the range , the probability that the final cell has label can be expressed in the form where . Output .
Input Format
The first line contains .
The next line contains .
Output Format
The probability of the final cell having label modulo for each in on separate lines.
3
1 1 1
0
500000004
500000004
4
3 1 1 1
666666672
0
166666668
166666668
Hint
For Sample 1:
There are two possibilities, where means that the cells with labels and merge into a new cell with label .
(1, 2) -> 2, (2, 3) -> 2
(2, 3) -> 3, (1, 3) -> 3
So with probability the final cell has label 2 or 3.
For Sample 2:
The six possibilities are as follows:
(1, 2) -> 1, (1, 3) -> 1, (1, 4) -> 1
(1, 2) -> 1, (3, 4) -> 4, (1, 4) -> 1
(2, 3) -> 3, (1, 3) -> 1, (1, 4) -> 1
(2, 3) -> 3, (3, 4) -> 3, (1, 3) -> 3
(3, 4) -> 4, (2, 4) -> 4, (1, 4) -> 4
(3, 4) -> 4, (1, 2) -> 1, (1, 4) -> 1
So with probability the final cell has label 1, and with probability the final cell has label 3 or 4.
SCORING:
- Input 3:
- Inputs 4-8:
- Inputs 9-14:
- Inputs 15-22: No additional constraints.