#P10102. [GDKOI2023 提高组] 矩阵

[GDKOI2023 提高组] 矩阵

Problem Description

You are given three n×nn \times n matrices AA, BB, and CC multiple times. You need to determine whether A×BA \times B is equal to CC modulo 998244353998244353.

Here, ×\times denotes matrix multiplication, and Ci,j=k=1nAi,kBk,jC_{i,j} = \sum_{k=1}^{n} A_{i,k} B_{k,j}.

The input size of this problem is large, so fast input reading is recommended.

Input Format

The first line contains a positive integer TT, the number of test cases.

Then there are TT test cases. In each test case, the first line contains a positive integer nn, the matrix size.

The next nn lines each contain nn integers, describing matrix AA.

The next nn lines each contain nn integers, describing matrix BB.

The next nn lines each contain nn integers, describing matrix CC.

Output Format

Output TT lines, each being Yes or No, indicating whether A×BA \times B is equal to CC modulo 998244353998244353.

3
1
2
3
6
2
1 2
3 4
5 6
7 8
19 22
43 51
2
1111111 2222222
3333333 4444444
5555555 6666666
7777777 8888888
39625305 256038638
772687616 944903942
Yes
No
Yes

Hint

For 20%20\% of the testdata, n300\sum n \le 300.

For another 20%20\% of the testdata, the number of positions where Ai,j0A_{i,j} \ne 0 does not exceed nn.

For 100%100\% of the testdata, 1T,n30001 \le T, n \le 3000, n3000\sum n \le 3000, and 0Ai,j,Bi,j,Ci,j<9982443530 \le A_{i,j}, B_{i,j}, C_{i,j} < 998244353.

Translated by ChatGPT 5