結果
問題 | No.1907 DETERMINATION |
ユーザー | Sumitacchan |
提出日時 | 2022-02-11 19:15:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,567 bytes |
コンパイル時間 | 3,517 ms |
コンパイル使用メモリ | 218,968 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-06-06 19:06:38 |
合計ジャッジ時間 | 25,915 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 239 ms
6,016 KB |
testcase_08 | AC | 99 ms
5,376 KB |
testcase_09 | AC | 169 ms
5,376 KB |
testcase_10 | AC | 504 ms
6,784 KB |
testcase_11 | AC | 111 ms
6,144 KB |
testcase_12 | AC | 566 ms
7,936 KB |
testcase_13 | AC | 538 ms
7,808 KB |
testcase_14 | AC | 497 ms
7,936 KB |
testcase_15 | AC | 119 ms
5,376 KB |
testcase_16 | AC | 33 ms
5,376 KB |
testcase_17 | AC | 478 ms
6,656 KB |
testcase_18 | AC | 336 ms
6,144 KB |
testcase_19 | AC | 11 ms
5,376 KB |
testcase_20 | AC | 511 ms
7,424 KB |
testcase_21 | AC | 51 ms
5,376 KB |
testcase_22 | AC | 306 ms
6,144 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 577 ms
8,192 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 597 ms
8,192 KB |
testcase_34 | AC | 597 ms
8,192 KB |
testcase_35 | WA | - |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | WA | - |
testcase_38 | AC | 574 ms
8,064 KB |
testcase_39 | AC | 576 ms
8,192 KB |
testcase_40 | WA | - |
testcase_41 | AC | 572 ms
8,320 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 564 ms
8,064 KB |
testcase_47 | AC | 588 ms
8,064 KB |
testcase_48 | AC | 579 ms
8,192 KB |
testcase_49 | AC | 573 ms
7,552 KB |
testcase_50 | AC | 577 ms
8,064 KB |
testcase_51 | AC | 572 ms
8,320 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 412 ms
6,400 KB |
testcase_54 | AC | 408 ms
6,272 KB |
testcase_55 | AC | 2 ms
5,376 KB |
testcase_56 | AC | 404 ms
6,272 KB |
testcase_57 | AC | 411 ms
6,400 KB |
testcase_58 | AC | 334 ms
6,656 KB |
testcase_59 | AC | 450 ms
8,192 KB |
testcase_60 | AC | 438 ms
8,192 KB |
testcase_61 | AC | 491 ms
7,552 KB |
testcase_62 | AC | 441 ms
8,192 KB |
testcase_63 | AC | 578 ms
8,192 KB |
testcase_64 | AC | 2 ms
5,376 KB |
testcase_65 | AC | 2 ms
5,376 KB |
testcase_66 | AC | 2 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; const int mod = 998244353; 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; } mvec solve(mmat A, mmat B){ /* X * O D の形にする ここで、X=xI-M (Mは定数行列), Dは定数のみの上三角行列 Xのサイズはrank(B) Dは正則でなければならない */ int N = A.size(); //まず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){ // M0+xM1は正則でないと信じる return mvec(N + 1, 0); } 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 ans = LibraryChecker::characteristic_polynomial(X); ans.resize(N + 1); REP(i, N + 1) ans[i] *= factor; return ans; } int main(){ int N; cin >> N; auto M0 = read_matrix(N); auto M1 = read_matrix(N); mint a = 63504649; // x=y-a とする mmat M0_2 = M0; REP(i, N) REP(j, N) M0_2[i][j] -= a * M1[i][j]; auto poly_y = solve(M0_2, M1); // y=x+aを代入して答えを得る // 二項係数 mmat ncr(N + 1, mvec(N + 1)); REP(i, N + 1){ ncr[i][0] = ncr[i][i] = 1; FOR(j, 1, i) ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j]; } mvec poly_x(N + 1); REP(i, N + 1) REP(j, i + 1){ poly_x[j] += poly_y[i] * ncr[i][j] * a.pow(i - j); } REP(i, N + 1) cout << poly_x[i].val() << endl; return 0; }