#P15764. [JAG 2025 Summer Camp #1] LOGCFL
[JAG 2025 Summer Camp #1] LOGCFL
题目描述
You are given a 3-dimensional integer array of size .
Initialize the following variables:
integer x = 0;
integer w = 1;
stack s = {};
Then, for each , choose an integer such that and do the following action:
If , do the following:
w *= A[t][x][y];
s.push(x);
x = y;
The above denotes .
If , do the following:
assert (!s.empty());
w *= A[t][x][s.top()];
x = (x + s.top()) % N;
s.pop();
You can't choose if the stack is empty before the action.
Note that the stack has the following operations:
- push(x): adds an element to the collection.
- pop(): removes the most recently added element.
- top(): returns the value of the most recently added element.
For each , consider all possible sequences such that the final value of is . Compute the sum of the corresponding values of over all such sequences, and output the result modulo .
输入格式
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}$$means the value of .
- $0 \leq A_{i,j,k} \leq 10^9 \ (1 \leq i, j, k \leq N)$
- All input values are integers.
输出格式
Output lines. On the -th line (), output the answer for .
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