File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ // @brief Adjugate Matrix
2+ #define PROBLEM " https://judge.yosupo.jp/problem/adjugate_matrix"
3+ #pragma GCC optimize("Ofast,unroll-loops")
4+ #include " cp-algo/linalg/matrix.hpp"
5+ #include < bits/stdc++.h>
6+
7+ const int mod = 998244353 ;
8+
9+ using namespace std ;
10+ using cp_algo::math::modint;
11+ using cp_algo::linalg::matrix;
12+
13+
14+ void solve () {
15+ int n;
16+ cin >> n;
17+ matrix<modint<mod>> A (n + 1 );
18+ for (int i: views::iota (0 , n)) {
19+ for (int j: views::iota (0 , n)) {
20+ cin >> A[i][j];
21+ }
22+ }
23+ for (int i: views::iota (0 , n)) {
24+ A[i][n] = cp_algo::random::rng ();
25+ A[n][i] = cp_algo::random::rng ();
26+ }
27+ auto Ai = A.inv ();
28+ auto D = A.det ();
29+ for (int i: views::iota (0 , n)) {
30+ for (int j: views::iota (0 , n)) {
31+ if (D != 0 ) {
32+ auto res = (*Ai)[n][n] * (*Ai)[i][j] - (*Ai)[i][n] * (*Ai)[n][j];
33+ cout << res * D << " \n " [j + 1 == n];
34+ } else {
35+ cout << 0 << " \n " [j + 1 == n];
36+ }
37+
38+ }
39+ }
40+ }
41+
42+ int main () {
43+ // freopen("input.txt", "r", stdin);
44+ ios::sync_with_stdio (0 );
45+ cin.tie (0 );
46+ solve ();
47+ return 0 ;
48+ }
You can’t perform that action at this time.
0 commit comments