結果

問題 No.2156 ぞい文字列
ユーザー take000take000
提出日時 2022-12-09 22:27:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 5,270 ms
コンパイル使用メモリ 253,292 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 22:35:58
合計ジャッジ時間 5,618 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 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;

struct Matrix {
    mint mat[2][2];
};

Matrix mul(Matrix a, Matrix b) {
    Matrix c;
    rep(i, 2) rep(j, 2) {
        c.mat[i][j] = 0;
        rep(k, 2) c.mat[i][j] += a.mat[i][k] * b.mat[k][j];
    }

    return c;
}

Matrix pow(Matrix a, ll n) {
    if (n == 1) return a;

    Matrix res;
    if (n % 2 == 0) {
        res = pow(a, n / 2);
        return mul(res, res);
    } else {
        res = pow(a, n - 1);
        return mul(res, a);
    }
}

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

    ll N;
    cin >> N;

    Matrix A = {{{1, 1}, {1, 0}}};
    Matrix B = pow(A, N);
    cout << (B.mat[0][0] - 1).val() << "\n";

    return 0;
}
0