結果

問題 No.2156 ぞい文字列
ユーザー take000take000
提出日時 2022-12-16 23:40:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 3,929 ms
コンパイル使用メモリ 271,772 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 22:39:49
合計ジャッジ時間 4,674 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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