No.2793 Mancala Master
Problem Statement
You are given a sequence of positive integers $A=(A_1,\ldots,A_N)$ and a positive integer $K$.
Koboshi plays the following game. Initially, the score is $1$, and for each $i=1,2,\ldots,N$, $A_i$ stones are placed at coordinate $i$.
Perform the following operation in the order $i=N,N-1,\ldots,1$.
- Move all stones at coordinate $i$, each to one of the coordinates $0,1,\ldots,i-1$. Letting $c_j$ be the number of stones moved to coordinate $j$, multiply the score by $f(c_0)f(c_1)\cdots f(c_{i-1})$. Here, $$ f(m)=\begin{cases} K^m-K^{m-1} & (m>0) \\ 1 & (m=0) \end{cases} $$ .
Find the sum of the final scores over all possible ways of performing the operations, modulo $998244353$.
You are given $T$ test cases; answer each of them.
Constraints
- $1\le T\le 10^5$
- $1\le N\le 2\times 10^5$
- $1\le A_i\lt 998244353$
- $2\le K\lt 998244353$
- All input values are integers.
- For the test cases in $1$ input, the sum of $N$ is at most $2\times 10^5$.
Input
The input is given from Standard Input in the following format.$T$
$\mathrm{case}_1$
$\vdots$
$\mathrm{case}_T$
Each case is given in the following format.
$N$ $K$ $A_1$ $A_2$ $\cdots$ $A_N$
Output
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th test case.
Sample
Sample 1
Input
1 2 10 1 2
Output
89100
First, move the $2$ stones at coordinate $2$.
- If both $2$ stones are moved to coordinate $0$, multiply the score by $10^2-10=90$. Next, move the $1$ stone at coordinate $1$ to coordinate $0$, and multiply the score by $10-1=9$.
- If both $2$ stones are moved to coordinate $1$, multiply the score by $10^2-10=90$. Next, move the $3$ stones at coordinate $1$ to coordinate $0$, and multiply the score by $10^3-10^2=900$.
- If $1$ stone each is moved to coordinates $0,1$, multiply the score by $(10-1)(10-1)=81$. Next, move the $2$ stones at coordinate $1$ to coordinate $0$, and multiply the score by $10^2-10=90$.
Therefore, the sum of the scores is $90\times 9+90\times 900+81\times 90=89100$.
Sample 2
Input
2 1 2 3 3 3281572 842184 12484 58238890
Output
4 724046312
Find the answer modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。