Skip to content

Commit 937230b

Browse files
committed
mat: det (mint only)
1 parent 39163cb commit 937230b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

mat.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,29 @@ struct Matrix {
2929
if (t&1) r = r*(*this);
3030
return r;
3131
}
32+
// https://youtu.be/-j02o6__jgs?t=11273
33+
/* mint only
34+
mint det() {
35+
assert(h == w);
36+
mint res = 1;
37+
rep(k,h) {
38+
for (int i = k; i < h; ++i) {
39+
if (d[i][k] == 0) continue;
40+
if (i != k) {
41+
swap(d[i],d[k]);
42+
res = -res;
43+
}
44+
}
45+
if (d[k][k] == 0) return 0;
46+
res *= d[k][k];
47+
mint inv = mint(1)/d[k][k];
48+
rep(j,h) d[k][j] *= inv;
49+
for (int i = k+1; i < h; ++i) {
50+
mint c = d[i][k];
51+
for (int j = k; j < h; ++j) d[i][j] -= d[k][j]*c;
52+
}
53+
}
54+
return res;
55+
}
56+
//*/
3257
};

0 commit comments

Comments
 (0)