-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28ae587
commit 0440f37
Showing
7 changed files
with
132 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @brief Pow of Matrix (Frobenius) | ||
#define PROBLEM "https://judge.yosupo.jp/problem/pow_of_matrix" | ||
#pragma GCC optimize("Ofast,unroll-loops") | ||
#pragma GCC target("avx2,tune=native") | ||
#include "cp-algo/linalg/frobenius.hpp" | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
using namespace cp_algo::algebra; | ||
using namespace cp_algo::linalg; | ||
|
||
const int mod = 998244353; | ||
using base = modular<mod>; | ||
using polyn = poly_t<base>; | ||
|
||
template<typename base> | ||
auto frobenius_pow(matrix<base> A, uint64_t k) { | ||
using polyn = poly_t<base>; | ||
auto [T, Tinv, charps] = frobenius_form<full>(A); | ||
vector<matrix<base>> blocks; | ||
for(auto charp: charps) { | ||
matrix<base> block(charp.deg()); | ||
auto xk = polyn::xk(1).powmod(k, charp); | ||
for(size_t i = 0; i < block.n(); i++) { | ||
ranges::copy(xk.a, begin(block[i])); | ||
xk = xk.mul_xk(1) % charp; | ||
} | ||
blocks.push_back(block); | ||
} | ||
auto S = matrix<base>::block_diagonal(blocks); | ||
return Tinv * S * T; | ||
} | ||
|
||
void solve() { | ||
size_t n; | ||
uint64_t k; | ||
cin >> n >> k; | ||
matrix<base> A(n); | ||
A.read(); | ||
frobenius_pow(A, k).print(); | ||
} | ||
|
||
signed main() { | ||
//freopen("input.txt", "r", stdin); | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
int t = 1; | ||
//cin >> t; | ||
while(t--) { | ||
solve(); | ||
} | ||
} |