Matrix Determinant

View as PDF

Submit solution

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


  • -18
    harry7557558  commented on April 18, 2020, 8:43 p.m. edit 249

    This comment is hidden due to too much negative feedback. Click here to view it.


    • 7
      ManchurioX  commented on April 20, 2020, 12:02 a.m.

      Hey! Spamming the "view previous" button on the comment above (the one with many edits) will get you captcha'd so be warned!!!


    • -1
      Moana  commented on April 19, 2020, 7:06 p.m. edit 4

      I got a proper PYPY2 AC submission.

      EDIT: DO NOT spam the "view history" button of the parent comment. To view its very first history, go to https://dmoj.ca/comments/12176/history/ajax?revision=0

      EDIT: Now the hardcoding sub is no longer the fastest submission.


  • 9
    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!


    • 0
      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?