結果
問題 | No.2883 K-powered Sum of Fibonacci |
ユーザー | t98slider |
提出日時 | 2024-09-08 14:02:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 244 ms / 3,000 ms |
コード長 | 6,173 bytes |
コンパイル時間 | 2,330 ms |
コンパイル使用メモリ | 208,852 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-08 14:02:18 |
合計ジャッジ時間 | 9,727 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
6,812 KB |
testcase_01 | AC | 23 ms
6,944 KB |
testcase_02 | AC | 26 ms
6,944 KB |
testcase_03 | AC | 28 ms
6,944 KB |
testcase_04 | AC | 21 ms
6,940 KB |
testcase_05 | AC | 52 ms
6,944 KB |
testcase_06 | AC | 61 ms
6,944 KB |
testcase_07 | AC | 64 ms
6,944 KB |
testcase_08 | AC | 63 ms
6,940 KB |
testcase_09 | AC | 59 ms
6,940 KB |
testcase_10 | AC | 210 ms
6,940 KB |
testcase_11 | AC | 214 ms
6,940 KB |
testcase_12 | AC | 199 ms
6,944 KB |
testcase_13 | AC | 220 ms
6,940 KB |
testcase_14 | AC | 210 ms
6,940 KB |
testcase_15 | AC | 199 ms
6,944 KB |
testcase_16 | AC | 218 ms
6,940 KB |
testcase_17 | AC | 209 ms
6,944 KB |
testcase_18 | AC | 202 ms
6,940 KB |
testcase_19 | AC | 204 ms
6,940 KB |
testcase_20 | AC | 224 ms
6,944 KB |
testcase_21 | AC | 211 ms
6,940 KB |
testcase_22 | AC | 225 ms
6,944 KB |
testcase_23 | AC | 218 ms
6,940 KB |
testcase_24 | AC | 223 ms
6,940 KB |
testcase_25 | AC | 237 ms
6,940 KB |
testcase_26 | AC | 237 ms
6,940 KB |
testcase_27 | AC | 237 ms
6,944 KB |
testcase_28 | AC | 244 ms
6,944 KB |
testcase_29 | AC | 202 ms
6,940 KB |
testcase_30 | AC | 7 ms
6,944 KB |
testcase_31 | AC | 9 ms
6,944 KB |
testcase_32 | AC | 12 ms
6,944 KB |
testcase_33 | AC | 12 ms
6,940 KB |
testcase_34 | AC | 14 ms
6,944 KB |
testcase_35 | AC | 223 ms
6,940 KB |
testcase_36 | AC | 220 ms
6,940 KB |
testcase_37 | AC | 192 ms
6,944 KB |
testcase_38 | AC | 218 ms
6,944 KB |
testcase_39 | AC | 210 ms
6,940 KB |
testcase_40 | AC | 11 ms
6,940 KB |
testcase_41 | AC | 7 ms
6,940 KB |
testcase_42 | AC | 201 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<const unsigned int MOD> struct prime_modint { using mint = prime_modint; unsigned int v; prime_modint() : v(0) {} prime_modint(unsigned int a) { a %= MOD; v = a; } prime_modint(unsigned long long a) { a %= MOD; v = a; } prime_modint(int a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; } prime_modint(long long a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; } static constexpr int mod() { return MOD; } mint& operator++() {v++; if(v == MOD)v = 0; return *this;} mint& operator--() {if(v == 0)v = MOD; v--; return *this;} mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint& operator+=(const mint& rhs) { v += rhs.v; if(v >= MOD) v -= MOD; return *this; } mint& operator-=(const mint& rhs) { if(v < rhs.v) v += MOD; v -= rhs.v; return *this; } mint& operator*=(const mint& rhs) { v = (unsigned int)((unsigned long long)(v) * rhs.v % MOD); return *this; } mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(long long n) const { assert(0 <= n); mint r = 1, x = *this; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mint inv() const { assert(v); return pow(MOD - 2); } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint& lhs, const mint& rhs) { return (lhs.v == rhs.v); } friend bool operator!=(const mint& lhs, const mint& rhs) { return (lhs.v != rhs.v); } friend std::ostream& operator << (std::ostream &os, const mint& rhs) noexcept { return os << rhs.v; } }; //using mint = prime_modint<1000000007>; using mint = prime_modint<998244353>; //enumeration<mint> enu(200000);のように宣言する template<class T> struct enumeration{ int N; vector<T> fact, inv; enumeration() : N(0), fact(1, 1), inv(1, 1) {} enumeration(int _n) : N(_n), fact(_n + 1), inv(_n + 1) { fact[0] = 1; for(int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i; inv[N] = T(1) / fact[N]; for(int i = N; i >= 1; i--) inv[i - 1] = inv[i] * i; } void expand(int lim){ fact.resize(lim + 1); inv.resize(lim + 1); for(int i = N + 1; i <= lim; i++) fact[i] = i * fact[i - 1]; inv[lim] = T(1) / fact[lim]; for(int i = lim; i >= N + 2; i--) inv[i - 1] = i * inv[i]; N = lim; } T Per(int n, int k){ if(k > n) return 0; if(n > N) expand(n); return fact[n] * inv[n - k]; } T C(int n, int k){ if(n < 0 || k < 0 || k > n) return 0; if(n > N) expand(n); return fact[n] * inv[n - k] * inv[k]; } T H(int n, int k){ if(n ==0 && k == 0) return 1; if(n <= 0 || k < 0) return 0; return C(n + k - 1, k); } }; template <class T, size_t N> struct Matrix { std::array<std::array<T, N>, N> A{}; Matrix() {} Matrix(const std::array<std::array<T, N>, N> &M) : A(M){} Matrix(const std::vector<std::vector<T>> &M) { for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ A[i][j] = M[i][j]; } } } const std::array<T, N>& operator[](int i) const { return A[i]; } std::array<T, N>& operator[](int i) { return A[i]; } Matrix& operator+=(const Matrix& rhs) { for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ A[i][j] += rhs[i][j]; } } return *this; } Matrix& operator-=(const Matrix& rhs) { for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ A[i][j] -= rhs[i][j]; } } return *this; } Matrix& operator*=(const Matrix& rhs) { std::array<std::array<T, N>, N> res{}; for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ for(size_t k = 0; k < N; k++){ res[i][j] += A[i][k] * rhs[k][j]; } } } swap(A, res); return *this; } Matrix& operator+() const { return *this; } Matrix& operator-() const { return Matrix() - *this; } friend Matrix operator+(const Matrix& lhs, const Matrix& rhs) { return Matrix(lhs) += rhs; } friend Matrix operator-(const Matrix& lhs, const Matrix& rhs) { return Matrix(lhs) -= rhs; } friend Matrix operator*(const Matrix& lhs, const Matrix& rhs) { return Matrix(lhs) *= rhs; } friend bool operator==(const Matrix& lhs, const Matrix& rhs) { return (lhs.A == rhs.A); } friend bool operator!=(const Matrix& lhs, const Matrix& rhs) { return (lhs.A != rhs.A); } Matrix pow(long long v){ Matrix res, temp = A; for(size_t i = 0; i < N; i++)res[i][i] = 1; while(v){ if(v & 1)res *= temp; temp *= temp; v >>= 1; } return res; } friend std::ostream& operator << (std::ostream &os, const Matrix& rhs) noexcept { for(size_t i = 0; i < N; i++){ if(i) os << '\n'; for(size_t j = 0; j < N; j++){ os << (j ? " " : "") << rhs[i][j]; } } return os; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; Matrix<mint, 102> Mt; enumeration<mint> enu(1000); for(int i = 0; i <= k; i++){ // F2**(i) * F1**(k-i) を求める for(int j = 0; j <= i; j++){ // F1**(j) * F0**(i-j) からの寄与 Mt[j + k - i][i] += enu.C(i, j); } } Mt[k][101] = Mt[101][101] = 1; auto B = Mt.pow(n); // cout << B << '\n'; mint ans = B[k][101]; cout << ans << '\n'; }