#P6673. [清华集训 2016] 石家庄的工人阶级队伍比较坚强

[清华集训 2016] 石家庄的工人阶级队伍比较坚强

Description

There are n=3mn=3^m people playing rock-paper-scissors. There are a total of tt rounds, and in each round there are mm games of rock-paper-scissors.

Within the mm games of the same round, each person’s decisions must be fixed in advance. That is, they cannot use a randomized strategy, and they cannot decide the next game based on the results of previous games. Therefore, there are clearly n=3mn=3^m possible strategies.

These n=3mn=3^m people will all use pairwise different strategies. For convenience, for person xx (0x<n0 \le x < n), convert xx to base 33 to get an mm-digit number, where 00 means scissors, 11 means rock, and 22 means paper. This gives the strategy used by person xx.

Since the indices are fixed, in the mm games of each round, everyone will always use the same set of decisions across different rounds.

Person xx initially has a score f0,xf_{0,x}.

In round ii, he will play mm games of rock-paper-scissors against another person yy.

Let W(x,y)W(x,y) be the number of wins of xx against yy in these mm games. Let L(x,y)L(x,y) be the number of losses of xx against yy.

After round ii ends, person xx’s score is:

fi,x=0y<nfi1,ybu,vf_{i,x}=\sum_{0 \le y < n} f_{i-1,y} b_{u,v}

where u=W(x,y)=L(y,x)u=W(x,y)=L(y,x) and v=L(x,y)=W(y,x)v=L(x,y)=W(y,x). Draws are not counted; bu,vb_{u,v} is a given scoring array.

Note that even if yy is the same as xx (transitioning from oneself to oneself), it will still be multiplied by a coefficient b0,0b_{0,0} (because playing against oneself results in all draws).

Obviously, as the number of rounds increases, the scores will grow larger. This scoring system, like computers in daily use, can overflow. When a score ff to be stored is greater than or equal to pp, it becomes fmodpf \bmod p.

Mr. B wants to know everyone’s scores after tt rounds, i.e., ft,0,ft,1,,ft,n1f_{t,0}, f_{t,1}, \ldots, f_{t,n-1}.

Mr. G: “Hey, I found that this number pp has a special property! There do not exist two positive integers such that the sum of their reciprocals equals 3/p3/p!”

Mr. B: “Mr. G is amazing! But how do we solve this problem?”

Input Format

The first line contains three integers m,t,pm, t, p.

The second line contains n=3mn=3^m integers, representing f0,0,f0,1,,f0,n1f_{0,0}, f_{0,1}, \ldots, f_{0,n-1}. It is guaranteed that 0f0,i<p0 \le f_{0,i} < p.

The following part is an array bb: the 1st line has m+1m+1 numbers, the 2nd line has mm numbers, ..., and the (m+1)(m+1)-th line has 11 number.

The jj-th number in the ii-th line is bi1,j1b_{i-1,j-1} (i,j1,i+j2mi,j \ge 1, i+j-2 \le m). It is guaranteed that 0bi,j<p0 \le b_{i,j} < p.

There do not exist two positive integers such that the sum of their reciprocals equals 3/p3/p. That is, there do not exist positive integers x,y>0x,y>0 such that 1/x+1/y=3/p1/x+1/y=3/p.

Output Format

Output n=3mn=3^m lines, each containing one integer, representing each person’s final score.

The ii-th line represents the ii-th person’s score ft,if_{t,i}.

1 1 10009
10 100 1000
2 3
4

4320
3240
2430

2 3 103
7 8 9 10 11 12 13 14 15
1 2 3
4 5
6

96
8
73
38
53
15
27
42
4

Hint

For all testdata, 0m120 \le m \le 12, 0t1090 \le t \le 10^9, 1p1091 \le p \le 10^9.

Translated by ChatGPT 5