結果

問題 No.2156 ぞい文字列
ユーザー take000
提出日時 2022-12-16 23:40:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 5,346 ms
コンパイル使用メモリ 259,932 KB
最終ジャッジ日時 2025-02-09 14:31:18
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace atcoder;
using namespace std;
using mint = modint998244353;

template <typename T>
struct mat {
    vector<vector<T>> M;
    int H = 0, W = 0;

    mat(int h, int w) {
        this->H = h;
        this->W = w;
        M = vector<vector<T>>(h, vector<T>(w));
    }

    mat(vector<vector<T>> &v) {
        this->H = v.size();
        this->W = v[0].size();
        M = v;
    }

    vector<T> operator[](int i) const { return M[i]; }
    vector<T> &operator[](int i) { return M[i]; }

    mat operator*(const mat &a) {
        mat res(H, a.W);
        rep(i, H) rep(k, W) rep(j, a.W) res[i][j] += M[i][k] * a[k][j];
        return res;
    }

    mat pow(ll n) {
        mat res(H, W);
        rep(i, H) res[i][i] = 1;
        mat a = *this;
        while (n) {
            if (n & 1) res = res * a;
            a = a * a;
            n >>= 1;
        }
        return res;
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);

    ll N;
    cin >> N;

    vector<vector<mint>> A = {{1, 1}, {1, 0}};
    mat<mint> a(A);
    mat<mint> b = a.pow(N);
    cout << (b[0][0] - 1).val() << "\n";

    return 0;
}
0