Characteristic Polynomial Verification solution codechef – 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,

Characteristic Polynomial Verification solution codechef

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+CM1AM10N(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.

Note: Characteristic Polynomial Verification solution codechef

  • Two matrices A,BA,B each with integer entries are said to be congruent modulo MM iff all entries of ABA−B are divisible by MM. This is denoted as AB(modM)A≡B(modM).
  • Since the input-output is large, prefer using fast input-output methods.

Input Format Characteristic Polynomial Verification solution codechef

  • 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,CM1C0,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.

Output Format Characteristic Polynomial Verification solution codechef

For each test case, output on a single line YES if the equation C0In+C1A+C2A2+CM1AM10N(mod998244353)C0In+C1A+C2A2+…CM−1AM−1≡0N(mod998244353) satisfies, and NO otherwise.

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).

Constraints Characteristic Polynomial Verification solution codechef

  • 1T2001≤T≤200
  • 1N10001≤N≤1000
  • 1M111≤M≤11
  • 0Ci<9982443530≤Ci<998244353
  • 0Ai,j<9982443530≤Ai,j<998244353
  • Sum of NN over all test cases does not exceed 20002000.

Subtasks Characteristic Polynomial Verification solution codechef

Subtask 1 (100 points): Original constraints

Sample Input 1  Characteristic Polynomial Verification solution codechef

2
3
998244351 998244348 1
2
1 2
3 4
3
998244351 998244348 1
2
1 1
1 1

Sample Output 1 Characteristic Polynomial Verification solution codechef

YES
NO

Explanation Characteristic Polynomial Verification solution codechef

Both test cases have the same co-efficients. Since 9982443512(mod998244353)998244351≡−2(mod998244353) and 9982443485(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=[1324]A=[1234], satisfies the equation 2I25A+A2=02−2I2−5A+A2=02, so the answer is YES.

Test case 22: For the given matrix, A=[1111]A=[1111], the left hand side of the equation evaluates to, 2I25A+A2=[5335]−2I2−5A+A2=[−5−3−3−5]. Clearly none of the entries are divisible by 998244353998244353, so the answer is NO.

Characteristic Polynomial Verification solution codechef

Ada is in charge of upgrading Chefland’s electrical network — she is implementing wireless electricity!

For simplicity, let’s consider Chefland a two-dimensional world, where the cities are represented by points on a plane and electric wires (which are not necessarily connecting the cities) are represented by straight line segments.

There are NN cities in Chefland (numbered 11 through NN) and MM wires (numbered 11 through MM). For each valid ii, the position of the ii-th city is (Xi,Yi)(Xi,Yi). Also, for each valid ii, the ii-th wire is a line segment with endpoints (Ai,Bi)(Ai,Bi) and (Ci,Di)(Ci,Di) initially.

Characteristic Polynomial Verification solution codechef

In order to transmit power, Ada built two plates (line segments): the positive plate, which has endpoints (1,0)(−1,0) and (0,1)(0,−1), and the negative plate, which has endpoints (106+1,106)(106+1,106) and (106,106+1)(106,106+1).

A wire is positive if it intersects the positive plate or intersects another wire about which we already know that it is positive. Similarly, a wire is negative if it intersects the negative plate or another negative wire. It is not allowed for any wire to be both positive and negative, because that creates a short-circuit.

Characteristic Polynomial Verification solution codechef

For each valid ii, let SiSi be the minimum of distances of the ii-th city from endpoints of positive wires, and let TiTi be the minimum of its distances from endpoints of negative wires. Then, the cost of transmitting electricity to the ii-th city is S2i+T2iSi2+Ti2. Let PP be the sum of these costs over all cities.

You are allowed to move the wires, but not to rotate them. For each valid ii, the cost of moving the ii-th segment by hihi units horizontally and vivi units vertically from its original position is h2i+v2ihi2+vi2. After such a move, the endpoints of the segment become (Ai+hi,Bi+vi)(Ai+hi,Bi+vi) and (Ci+hi,Di+vi)(Ci+hi,Di+vi). Let QQ be the sum of costs of moving all the wires.

Your goal is to move the wires and make P+QP+Q as small as possible. In the final network of wires, there should be at least one positive wire, at least one negative wire, and no wire should be both positive and negative. However, it is allowed to have some wires that are neither positive nor negative.

Characteristic Polynomial Verification solution codechef

Input Characteristic Polynomial Verification solution codechef

  • The first line of the input contains two space-separated integers NN and MM.
  • NN lines follow. For each valid ii, the ii-th of these lines contains two space-separated integers XiXi and YiYi.
  • MM more lines follow. For each valid ii, the ii-th of these lines contains four space-separated integers AiAiBiBiCiCi and DiDi.

Output Characteristic Polynomial Verification solution codechef

Print MM lines. For each valid ii, the ii-th of these lines should contain two space-separated integers hihi and vivi denoting that the ii-th wire is moved by hihi (|hi|106|hi|≤106) units horizontally and by vivi (|vi|106|vi|≤106) units vertically.

Example Input Characteristic Polynomial Verification solution codechef

4 4
1 1
2 2
3 3
4 4
0 0 4 2
3 5 4 2
4 5 2 4
1 5 3 2

Example Output

-1 0
-1 0
-1 1
2 0

Explanation Characteristic Polynomial Verification solution codechef

The following figure shows the cities AABBCC and DD, the positive plate EFEF, negative plate GHGH and the wires IJIJKLKLMNMN and OPOP. Note that the negative plate is drawn closer for clarity.

Characteristic Polynomial Verification solution codechef

The following figure describes the state after moving the wires.

Characteristic Polynomial Verification solution codechef

Test Generation Characteristic Polynomial Verification solution codechef

The source code used to generate test data can be downloaded here.

  • N=104N=104
  • M=2500M=2500
  • all coordinates of the NN cities are chosen uniformly randomly and independently among integers between 00 and 106106 inclusive
  • for each valid iiXiXi and YiYi are chosen uniformly randomly and independently among integers between 00 and 106106 inclusive
  • a parameter LL is chosen: LL can be 8,0008,00010,00010,00012,00012,00014,00014,000 or 16,00016,000
  • For each ii from 11 to MM:
    • two integers hihi and vivi different than zero are chosen uniformly randomly and independently between L−L and LL inclusive
    • AiAi is chosen uniformly randomly among integers between max(0,hi)max(0,−hi) and min(106,106hi)min(106,106−hi) inclusive
    • BiBi is chosen uniformly randomly among integers between max(0,vi)max(0,−vi) and min(106,106vi)min(106,106−vi) inclusive
    • Ci=Ai+hiCi=Ai+hi
    • Di=Bi+viDi=Bi+vi

There are two test files for each possible value of LL.

Scoring Characteristic Polynomial Verification solution codechef

The source code used to determine the score of your solution can be downloaded here.

If your output is invalid, in particular if there is no positive wire, no negative wire, or if some wire is declared both positive and negative, you will receive the Wrong Answer verdict.

Characteristic Polynomial Verification solution codechef

The score for each test case (and therefore each test file) is P+QP+Q. The score of a submission is equal to the sum of its scores over all test cases. Your goal is to minimise the score of your submission.

There are 10 test files. During the contest, the displayed score will account for exactly 5 test files, i.e. your score reflects your submission’s performance on 50% (5/10) of the test files. However, if your program gets a non-AC verdict on any test file, your submission’s verdict will be non-AC. In other words, an AC verdict denotes that your program runs successfully on all the test files. After the end of the contest, your score will be changed to include the sum of your program’s scores over the other 5 test files.

Leave a Reply

Your email address will not be published. Required fields are marked *

*