#P5293. [HNOI2019] 白兔之舞

    ID: 4237 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2019各省省选湖南容斥快速傅里叶变换 FFT

[HNOI2019] 白兔之舞

Description

There is a directed graph with (L+1)×n(L+1)\times n vertices. Each vertex is represented by an ordered pair (u,v)(u,v), where (0uL,1vn)(0\le u\le L,1\le v\le n).

This graph is not a simple graph. For any two vertices (u1,v1)(u2,v2)(u_1,v_1)(u_2,v_2), if u1<u2u_1<u_2, then there are exactly w[v1][v2]w[v_1][v_2] different edges from (u1,v1)(u_1,v_1) to (u2,v2)(u_2,v_2). If u1u2u_1\ge u_2, then there is no edge.

The white rabbit will perform a dance on this graph. Initially, it is at vertex (0,x)(0,x).

The white rabbit will make several jumps. In each jump, it moves from the current vertex to the next vertex along any outgoing edge. It can stop at any time (it may also stop immediately without making any jump). When it reaches a vertex whose first coordinate is LL, it must stop, because that vertex has no outgoing edges.

Suppose the rabbit stops after making mm jumps. It will record this dance as a sequence, whose ii-th element is the edge it took in its ii-th jump.

Now, given positive integers kk and yy (1yn1\le y\le n), for each tt (0t<k0\le t<k), find how many dances (with length mm) satisfy mmodk=tm \bmod k=t, and the rabbit finally stops at a vertex whose second coordinate is yy.

Two dances are considered different if their lengths (mm) are different, or there exists some step at which the edges they take are different.

Output the results modulo pp.

Input Format

The input file name is dance.in.

The first line contains five integers n,k,L,x,y,pn,k,L,x,y,p separated by spaces.

Then follow nn lines, each containing nn integers separated by spaces. The jj-th number in the ii-th line denotes w[i][j]w[i][j].

Output Format

The output file name is dance.out.

Output kk lines in order, each containing one number: the answer modulo pp.

2 2 3 1 1 998244353
2 1
1 0
16
18
3 4 100 1 3 998244353
1 1 1
1 1 1
1 1 1
506551216
528858062
469849094
818871911

Hint

Sample Explanation 1

t=0t=0:

  1. Path length is 00, and the number of ways is 11.
  2. Path length is 22. There are six types of paths:
    • (0,1)(1,1)(2,1)(0,1)\to (1,1)\to (2,1): this path has w(1,1)×w(1,1)=4w(1,1)\times w(1,1)=4 ways;
    • (0,1)(1,1)(3,1)(0,1)\to (1,1)\to (3,1): this path has w(1,1)×w(1,1)=4w(1,1)\times w(1,1)=4 ways;
    • (0,1)(2,1)(3,1)(0,1)\to (2,1)\to (3,1): this path has w(1,1)×w(1,1)=4w(1,1)\times w(1,1)=4 ways;
    • (0,1)(1,2)(2,1)(0,1)\to (1,2)\to (2,1): this path has w(1,2)×w(2,1)=1w(1,2)\times w(2,1)=1 way;
    • (0,1)(1,2)(3,1)(0,1)\to (1,2)\to (3,1): this path has w(1,2)×w(2,1)=1w(1,2)\times w(2,1)=1 way;
    • (0,1)(2,2)(3,1)(0,1)\to (2,2)\to (3,1): this path has w(1,2)×w(2,1)=1w(1,2)\times w(2,1)=1 way;

So the answer is 1+4+4+4+1+1+1=161+4+4+4+1+1+1=16.

t=1t=1:

  1. Path length is 11. There are three types of paths:
    • (0,1)(1,1)(0,1)\to (1,1): this path has w(1,1)=2w(1,1)=2 ways;
    • (0,1)(2,1)(0,1)\to (2,1): this path has w(1,1)=2w(1,1)=2 ways;
    • (0,1)(3,1)(0,1)\to (3,1): this path has w(1,1)=2w(1,1)=2 ways;
  2. Path length is 33. There are three types of paths:
    • (0,1)(1,1)(2,1)(3,1)(0,1)\to (1,1)\to (2,1)\to (3,1): this path has w(1,1)×w(1,1)×w(1,1)=8w(1,1)\times w(1,1)\times w(1,1)=8 ways;
    • (0,1)(1,1)(2,2)(3,1)(0,1)\to (1,1)\to (2,2)\to (3,1): this path has w(1,1)×w(1,2)×w(2,1)=2w(1,1)\times w(1,2)\times w(2,1)=2 ways;
    • (0,1)(1,2)(2,1)(3,1)(0,1)\to (1,2)\to (2,1)\to (3,1): this path has w(1,2)×w(2,1)×w(1,1)=2w(1,2)\times w(2,1)\times w(1,1)=2 ways;

So the answer is 2+2+2+8+2+2=182+2+2+8+2+2=18.

Constraints

For all testdata, pp is a prime number, 108<p<23010^8<p<2^{30}, 1n31\le n\le 3, 1xn1\le x\le n, 1yn1\le y\le n, 0w(i,j)<p0\le w(i,j)<p, 1k655361\le k\le 65536, kk is a divisor of p1p-1, and 1L1081\le L\le 10^8.

For each test point, the special constraints are as follows:

  • Test points 1,21,2: L105L\le 10^5;
  • Test point 33: n=1,w(1,1)=1n=1,w(1,1)=1, and the largest prime factor of kk is 22;
  • Test point 44: n=1n=1, and the largest prime factor of kk is 22;
  • Test point 55: n=1,w(1,1)=1n=1,w(1,1)=1;
  • Test point 66: n=1n=1;
  • Test points 7,87,8: the largest prime factor of kk is 22.

Translated by ChatGPT 5