結果
問題 | No.1907 DETERMINATION |
ユーザー | Sumitacchan |
提出日時 | 2022-02-05 19:23:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,817 bytes |
コンパイル時間 | 2,499 ms |
コンパイル使用メモリ | 217,124 KB |
実行使用メモリ | 6,528 KB |
最終ジャッジ日時 | 2024-06-06 18:58:45 |
合計ジャッジ時間 | 30,941 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | RE | - |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 234 ms
5,376 KB |
testcase_08 | AC | 94 ms
5,376 KB |
testcase_09 | AC | 163 ms
5,376 KB |
testcase_10 | AC | 466 ms
5,376 KB |
testcase_11 | RE | - |
testcase_12 | AC | 526 ms
6,144 KB |
testcase_13 | AC | 515 ms
6,016 KB |
testcase_14 | AC | 498 ms
6,016 KB |
testcase_15 | AC | 113 ms
5,376 KB |
testcase_16 | AC | 32 ms
5,376 KB |
testcase_17 | AC | 445 ms
5,376 KB |
testcase_18 | AC | 313 ms
5,376 KB |
testcase_19 | AC | 11 ms
5,376 KB |
testcase_20 | AC | 490 ms
5,760 KB |
testcase_21 | AC | 46 ms
5,376 KB |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 571 ms
6,272 KB |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | AC | 544 ms
6,272 KB |
testcase_34 | AC | 543 ms
6,400 KB |
testcase_35 | RE | - |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | RE | - |
testcase_38 | AC | 562 ms
6,528 KB |
testcase_39 | AC | 545 ms
6,272 KB |
testcase_40 | RE | - |
testcase_41 | AC | 569 ms
6,400 KB |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | AC | 528 ms
6,272 KB |
testcase_47 | AC | 534 ms
6,400 KB |
testcase_48 | AC | 546 ms
6,400 KB |
testcase_49 | AC | 539 ms
5,760 KB |
testcase_50 | AC | 534 ms
6,272 KB |
testcase_51 | AC | 550 ms
6,400 KB |
testcase_52 | RE | - |
testcase_53 | RE | - |
testcase_54 | RE | - |
testcase_55 | RE | - |
testcase_56 | RE | - |
testcase_57 | RE | - |
testcase_58 | AC | 315 ms
5,376 KB |
testcase_59 | AC | 407 ms
6,400 KB |
testcase_60 | AC | 406 ms
6,272 KB |
testcase_61 | AC | 466 ms
5,888 KB |
testcase_62 | AC | 412 ms
6,272 KB |
testcase_63 | AC | 541 ms
6,400 KB |
testcase_64 | AC | 2 ms
5,376 KB |
testcase_65 | AC | 2 ms
5,376 KB |
testcase_66 | AC | 1 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using namespace atcoder; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define IREP(i, n) IFOR(i,0,n) using ll = long long; using mint = modint998244353; using mvec = vector<mint>; using mmat = vector<mvec>; #define debug(x) cout << #x << "=" << x << endl; #define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, (int)v.size()){ cout << v[i_debug] << ","; } cout << endl; } #define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, (int)m.size()){ REP(j_debug, (int)m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} } // Library Checker "Characteristic Polynomial" より引用 // https://judge.yosupo.jp/submission/68640 namespace LibraryChecker { template <typename T> std::vector<T> characteristic_polynomial(std::vector<std::vector<T>> M) { assert(M.empty() or M.size() == M[0].size()); int n = M.size(); // reduce M to upper Hessenberg form for (int j = 0; j < n - 2; j++) { for (int i = j + 2; i < n; i++) { if (M[i][j] != 0) { std::swap(M[j + 1], M[i]); for (int k = 0; k < n; k++) std::swap(M[k][j + 1], M[k][i]); break; } } if (M[j + 1][j] == 0) continue; auto inv = T(1) / M[j + 1][j]; for (int i = j + 2; i < n; i++) { auto coef = M[i][j] * inv; for (int k = j; k < n; k++) M[i][k] -= coef * M[j + 1][k]; for (int k = 0; k < n; k++) M[k][j + 1] += coef * M[k][i]; } } // compute the characteristic polynomial of upper Hessenberg matrix M std::vector<std::vector<T>> p(n + 1); p[0] = {T(1)}; for (int i = 0; i < n; i++) { p[i + 1].resize(i + 2); for (int j = 0; j <= i; j++) { p[i + 1][j + 1] += p[i][j]; p[i + 1][j] -= p[i][j] * M[i][i]; } T betas = 1; for (int j = i - 1; j >= 0; j--) { betas *= M[j + 1][j]; T coef = -betas * M[j][i]; for (int k = 0; k <= j; k++) p[i + 1][k] += coef * p[j][k]; } } return p[n]; } } // namespace LibraryChecker mmat read_matrix(int N){ mmat M(N, mvec(N)); REP(i, N) REP(j, N){ int x; cin >> x; M[i][j] = x; } return M; } void write_matrix(mmat M){ int N = M.size(); REP(i, N){ REP(j, N) cout << M[i][j].val() << ','; cout << endl; } } //swap M[i,:] and M[j,:] void swap_row(mmat &M, int i, int j){ assert(i != j); M[i].swap(M[j]); } //swap M[:,i] and M[:,j] void swap_column(mmat &M, int i, int j){ assert(i != j); int N = M.size(); REP(k, N) swap(M[k][i], M[k][j]); } //M[i,:]-=a*M[j:] void sbt_row(mmat &M, int i, int j, mint a){ assert(i != j); int N = M.size(); REP(k, N) M[i][k] -= a * M[j][k]; } //M[:,i]-=a*M[:,j] void sbt_column(mmat &M, int i, int j, mint a){ assert(i != j); int N = M.size(); REP(k, N) M[k][i] -= a * M[k][j]; } //M[i,:]*=a; void mult_row(mmat &M, int i, mint a){ int N = M.size(); REP(k, N) M[i][k] *= a; } int main(){ int N; cin >> N; auto A = read_matrix(N); auto B = read_matrix(N); /* X * O D の形にする ここで、X=xI-M (Mは定数行列), Dは定数のみの上三角行列 Xのサイズはrank(B) Dは正則でなければならない */ //まずX求める int rankB = 0; mint factor = 1; REP(d, N){ int x = -1, y = -1; FOR(i, d, N){ FOR(j, d, N){ if(B[i][j].val() != 0){ x = i; y = j; break; } } if(x != -1) break; } if(x == -1) break; rankB++; if(x != d){ swap_row(A, x, d); swap_row(B, x, d); factor *= -1; } if(y != d){ swap_column(A, y, d); swap_column(B, y, d); factor *= -1; } FOR(i, d + 1, N){ mint a = B[i][d] / B[d][d]; sbt_row(A, i, d, a); sbt_row(B, i, d, a); } FOR(j, d + 1, N){ mint a = B[d][j] / B[d][d]; sbt_column(A, j, d, a); sbt_column(B, j, d, a); } factor *= B[d][d]; mult_row(A, d, (mint)1 / B[d][d]); B[d][d] = 1; } // 右下整理してDを求める FOR(d, rankB, N){ int x = -1, y = -1; FOR(i, d, N){ FOR(j, d, N){ if(A[i][j].val() != 0){ x = i; y = j; break; } } if(x != -1) break; } if(x == -1) assert(false); if(x != d){ swap_row(A, x, d); factor *= -1; } if(y != d){ swap_column(A, y, d); factor *= -1; } FOR(i, d + 1, N){ mint a = A[i][d] / A[d][d]; sbt_row(A, i, d, a); } FOR(j, 0, d){ mint a = A[d][j] / A[d][d]; sbt_column(A, j, d, a); } } IFOR(d, rankB, N){ FOR(j, 0, d){ mint a = A[d][j] / A[d][d]; sbt_column(A, j, d, a); } factor *= A[d][d]; } mmat X(rankB, mvec(rankB)); REP(i, rankB) REP(j, rankB) X[i][j] = -A[i][j]; auto res = LibraryChecker::characteristic_polynomial(X); res.resize(N + 1); REP(i, N + 1) res[i] *= factor; REP(i, N + 1) cout << res[i].val() << endl; return 0; }