luogu#P9382. [THUPC 2023 决赛] Freshman Dream
[THUPC 2023 决赛] Freshman Dream
Problem Description
Little J is learning matrix multiplication.
Little L tells him: as long as you multiply the elements in the same positions of two matrices, you can get the product of the two matrices.
This is of course wrong, but Little L wants to keep fooling Little J. So, she needs to put a matrix multiplication problem on her own OJ such that this kind of “matrix multiplication” can also produce the correct answer.
Because Little L’s OJ runs very slowly and has a very small memory limit, the answers in this matrix multiplication problem are all taken modulo .
Now Little L starts generating testdata. She first randomly generates an matrix . Specifically, each element is with probability , and otherwise, and these events are independent. Now, she still needs to design another matrix , such that .
Little L tried generating matrices randomly, but could not find any matrix that meets the requirement; she tried constructing some matrices and found she could only construct the all-zero matrix, which is too obvious. Now she hands the task of generating testdata to you: you need to give a that meets the requirement. At the same time, to avoid making it look suspicious, she additionally requires that contains exactly ones.
Input Format
Read from standard input.
The first line contains two positive integers , representing the matrix size and the in the statement.
The next lines each contain integers , representing the elements of .
Output Format
Write to standard output.
If there is no that satisfies the requirement, output one line containing one integer .
Otherwise, first output one line containing one integer , then output lines, each containing integers in to represent the elements of matrix . If there are multiple possible , output any one of them.
3 3
1 0 0
0 1 0
0 0 1
1
1 0 0
0 1 0
0 0 1
Hint
Sample Explanation #1
Here is the identity matrix, and the constructed is also the identity matrix, so the product is also the identity matrix. At the same time, multiplying the corresponding positions also gives the identity matrix, and contains exactly ones, so it satisfies the requirement.
In this sample, is not , but it is guaranteed that in all testdata is .
Constraints
For all testdata, , , , and all are independent and uniformly random.
Source
From the finals of the 2023 Tsinghua University Student Programming Contest and Collegiate Invitational (THUPC2023).
Resources such as the editorial can be found at https://github.com/THUSAAC/THUPC2023.
Translated by ChatGPT 5