We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 39163cb commit 937230bCopy full SHA for 937230b
mat.cpp
@@ -29,4 +29,29 @@ struct Matrix {
29
if (t&1) r = r*(*this);
30
return r;
31
}
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
+ //*/
57
};
0 commit comments