Problem 352
Matrix Determinant
Medium · 20 pts · Math, Matrix
Problem
Compute the determinant of an N x N matrix of integers. The determinant of a 2 x 2 matrix [[a, b], [c, d]] is ad - bc; for larger matrices, expand along a row (Laplace expansion) or use Gaussian elimination. The entries are integers, so the determinant is an integer too. Be careful with floating-point rounding if you use elimination.
Input
First line: N. Next N lines: N integers each.
Output
Print the determinant.
Constraints
1 <= N <= 8; -10 <= value <= 10
Example input
2 1 2 3 4
Example output
-2
Explanation
The matrix is [[1, 2], [3, 4]], so the 2 x 2 formula ad - bc gives 1 · 4 - 2 · 3 = -2.