Characteristic Polynomial Verification CHARVER
Given an array CC of MM integers and a square matrix AA (with integer entries) of dimension N×NN×N, verify whether the following equation is true,C0IN+C1A+C2A2+…CM−1AM−1≡0N(mod998244353)C0IN+C1A+C2A2+…CM−1AM−1≡0N(mod998244353)
where 0N0N is the square null matrix (matrix in which all elements are zero) and ININ is the identity matrix, both having dimensions N×NN×N.
- Two matrices A,BA,B each with integer entries are said to be congruent modulo MM iff all entries of A−BA−B are divisible by MM. This is denoted as A≡B(modM)A≡B(modM).
- Since the input-output is large, prefer using fast input-output methods.
- The first line contains TT denoting the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer MM denoting the length of CC.
- The second line of each testcase contains MM space separated integers, C0,C1,…CM−1C0,C1,…CM−1 representing the array CC.
- The third line of each testcase contains a single integer NN denoting the size of the square matrix AA.
- The ii-th line of the next NN lines contains NN space-separated integers Ai,1,Ai,2,…,Ai,NAi,1,Ai,2,…,Ai,N denoting the elements of the ii-th row of the matrix AA.
For each test case, output on a single line
YES if the equation C0In+C1A+C2A2+…CM−1AM−1≡0N(mod998244353)C0In+C1A+C2A2+…CM−1AM−1≡0N(mod998244353) satisfies, and
Output is case insensitive, i.e., you may print each character of the string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).
- Sum of NN over all test cases does not exceed 20002000.
Subtask 1 (100 points): Original constraints
Sample Input 1
2 3 998244351 998244348 1 2 1 2 3 4 3 998244351 998244348 1 2 1 1 1 1
Sample Output 1
Both test cases have the same co-efficients. Since 998244351≡−2(mod998244353)998244351≡−2(mod998244353) and 998244348≡−5(mod998244353)998244348≡−5(mod998244353), for convenience of explanation, we shall take the co-efficients as −2,−5,1−2,−5,1. Note that this does not affect the answer.
Test case 11: The given matrix, A=A=, satisfies the equation −2I2−5A+A2=02−2I2−5A+A2=02, so the answer is
Test case 22: For the given matrix, A=A=, the left hand side of the equation evaluates to, −2I2−5A+A2=[−5−3−3−5]−2I2−5A+A2=[−5−3−3−5]. Clearly none of the entries are divisible by 998244353998244353, so the answer is
Solution will be updated soon mean while keep trying..
October Long Challenge 2021
- Longest AND Subarray
- Digit Removal
- Yet another MEX problem
- Characteristic Polynomial Verification
- Chef at the Olympics
- Which Mixture
- Three Boxes