Matrix Determinant

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 2.0s
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


  • 8
    FatalEagle  commented on Jan. 20, 2015, 3: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!


    • 1
      bobhob314  commented on Jan. 26, 2015, 2:25 p.m.

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


      • 1
        bobhob314  commented on Jan. 26, 2015, 2:25 p.m.

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