#P8979. 「DTOI-4」白的 Fibonacci

    ID: 9762 远端评测题 1500ms 64MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2023多项式洛谷原创O2优化线性递推

「DTOI-4」白的 Fibonacci

Problem Description

Define F(k,n)F(k, n) as follows:

$$F(k,n) = \left \{ \begin{aligned} &st_0\ && k = 1\ \land\ n = 0 \\ &st_1\ && k = 1\ \land\ n = 1 \\ &0\ && k > 1 \ \land \ n < 0 \\ &a \times F(k, n - 1) + b \times F(k, n - 2)\ && k = 1 \ \land\ n > 1 \\ &t_k \times F(k, n - 1) + s^n \times F(k - 1, n)\ && \text{otherwise} \end{aligned} \right.$$

Given the coefficients in the recurrence of FF and k,nk, n, compute the value of F(k,n)mod998244353F(k, n) \bmod 998244353.

Input Format

The first line contains two integers k,nk, n.

The second line contains five integers st0,st1,a,b,sst_0, st_1, a, b, s.

The third line contains k1k - 1 integers t2,t3,,tkt_2, t_3, \cdots, t_k.

Output Format

Output one integer on a single line, which is the answer.

10 25
-5 -73 -95 64 15
-80 -31 -58 15 95 -1 14 -30 31 
998096342

Hint

Subtask\textbf{Subtask} kk \leq nn \leq Special Property Score
11 100100 100100 None 55
22 2632^{63} 2525
33 50005000 s=1,2ik,ti=1s = 1, \forall 2 \leq i \leq k, t_i = 1 1010
44 None 6060

For 100%100\% of the testdata, 1k5×1031 \leq k \leq 5 \times 10^3, 0n2630 \leq n \le 2^{63}, and $-998244352 \leq st_0, st_1, a, b, s, t_i \leq 998244352$.

Translated by ChatGPT 5