## Matrix Determinant

View as PDF

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

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

FatalEagle recently stumbled upon a manga that teaches linear algebra. A particularly interesting topic was matrix determinants. Your task is simple: given , an matrix, find its determinant! Since this number can be really big, we want to find its value .

#### Input Specification

The first line of input will have .

The next lines will have integers each. The integer of the line will contain .

For cases worth 30% of the total marks, .

For cases worth another 30% of the total marks, .

For all test cases, .

#### Output Specification

The output should be a single integer in the range , the determinant of the matrix .

#### 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

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

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

• commented on April 19, 2020, 7:06 p.m. edit 6

Comment by harry7557558: original edit 2 edit 6 edit 12 edit 13+; Account kicked out for spam requesting and is currently inaccessible.

The proper Python submission has an average complexity of ; Current fastest submission uses addition/multiplication/modulo operations (++ inside for loop doesn't count) and modular multiplicative inverse operations, when is large; This C++ submission works without #pragma and uses a "proper" IO. (typo in header comment: "peering" -> "peeping")

• The determinant of an upper-triangular matrix is the product of all diagonal elements;
• Add the multiple of one row to another row (element-wise) does not change the determinant of a matrix;
• When two rows of a matrix are swapped, the determinant of the matrix changes sign;

Some facts related to the comment with many edits:

Edited Oct.13, 2020.

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

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

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

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