Matrix Determinant

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 0.1s
Java 0.2s
Python 0.2s
Memory limit: 256M

Author:
Problem type

FatalEagle recently stumbled upon a manga that teaches linear algebra. A particularly interesting topic was matrix determinants. Your task is simple: given A, an N \times N matrix, find its determinant! Since this number can be really big, we want to find its value \bmod 1\,000\,000\,007 (10^9+7).

Input Specification

The first line of input will have N.

The next N lines will have N integers each. The j^{th} integer of the i^{th} line will contain A_{i,j} (-10^9 \le A_{i,j} \le 10^9).

For cases worth 30% of the total marks, 1 \le N \le 8.

For cases worth another 30% of the total marks, 1 \le N \le 20.

For all test cases, 1 \le N \le 500.

Output Specification

The output should be a single integer in the range [0, 1\,000\,000\,007), the determinant of the matrix A.

Sample Input 1

2
-1 3
-5 7

Sample Output 1

8

Sample Input 2

6
1 3 5 2 4 6
2 5 4 3 1 6
6 1 2 3 4 5
2 5 1 3 6 4
4 5 1 2 3 6
5 4 3 6 1 2

Sample Output 2

2457

Comments


  • 3
    Plasmatic  commented on July 5, 2021, 5:34 a.m.

    If you would like to test your determinant code but are getting TLE on this problem here is an alternative (on another judge) that has a 5 second TL if you want to see it run on some larger cases.


  • -33
    harry7557558  commented on April 19, 2020, 12:43 a.m. edit 250

    This comment is hidden due to too much negative feedback. Show it anyway.


  • 11
    FatalEagle  commented on Jan. 20, 2015, 8:32 p.m.

    There are a large number of test cases with increasing size. This problem is to test the efficiency of your matrix determinant algorithm -- in other words, the constant matters in this question!


    • 0
      bobhob314  commented on Jan. 26, 2015, 7:25 p.m. edited

      Wait Fatal so you mean e.g. for T(n) = \mathcal{O}(f(n)), if f(n) were to be 2n^3 or something, then the 2 coefficient would matter?


      • 0
        bobhob314  commented on Jan. 26, 2015, 7:25 p.m.

        Or sorry, I goofed. What do you mean by constant?