#P15764. [JAG 2025 Summer Camp #1] LOGCFL

[JAG 2025 Summer Camp #1] LOGCFL

题目描述

You are given a 3-dimensional integer array AA of size N×N×NN \times N \times N.

Initialize the following variables:

integer x = 0;
integer w = 1;
stack s = {};

Then, for each t=0,1,,N1t = 0, 1, \ldots, N - 1, choose an integer yty_t such that 1yt<N-1 \leq y_t < N and do the following action:

If 0yt0 \leq y_t, do the following:

w *= A[t][x][y];
s.push(x);
x = y;

The above yy denotes yty_t.

If yt=1y_t = -1, do the following:

assert (!s.empty());
w *= A[t][x][s.top()];
x = (x + s.top()) % N;
s.pop();

You can't choose yt=1y_t = -1 if the stack is empty before the action.

Note that the stack has the following operations:

  • push(x): adds an element xx to the collection.
  • pop(): removes the most recently added element.
  • top(): returns the value of the most recently added element.

For each i=0,1,,N1i = 0, 1, \ldots, N - 1, consider all possible sequences y0,y1,,yN1y_0, y_1, \ldots, y_{N-1} such that the final value of xx is ii. Compute the sum of the corresponding values of ww over all such sequences, and output the result modulo 998244353998244353.

输入格式

The input is given in the following format:

$$\begin{aligned} & N \\ & A_{0,0,0} \cdots A_{0,0,N-1} \\ & \vdots \\ & A_{0,N-1,0} \cdots A_{0,N-1,N-1} \\ & \vdots \\ & \vdots \\ & A_{N-1,0,0} \cdots A_{N-1,0,N-1} \\ & \vdots \\ & A_{N-1,N-1,0} \cdots A_{N-1,N-1,N-1} \end{aligned}$$

Ai,j,kA_{i,j,k} means the value of A[i][j][k]A[i][j][k].

  • 1N301 \leq N \leq 30
  • $0 \leq A_{i,j,k} \leq 10^9 \ (1 \leq i, j, k \leq N)$
  • All input values are integers.

输出格式

Output NN lines. On the ii-th line (0i<N0 \leq i < N), output the answer for ii.

2
1 10
100 1000
1 3
9 27
92
363
3
2 1 2
1 2 1
1 1 1
2 1 1
2 2 1
2 2 2
2 1 1
1 2 1
1 2 2
63
68
56
4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
120
120
120
120