結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー PachicobuePachicobue
提出日時 2018-07-28 03:40:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,055 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 198,616 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-19 05:54:14
合計ジャッジ時間 3,293 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//=================================
// Created on: 2018/07/28 00:18:13
//=================================
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
constexpr ll MOD = 1000000007LL;
using V = std::array<ll, 4>;
using M = std::array<V, 4>;
M mul(const M& m1, const M& m2)
{
    M ans{{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}};
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) { (ans[i][j] += m1[i][k] * m2[k][j]) %= MOD; }
        }
    }
    return ans;
}
M pow(const M& m, const ll n)
{
    if (n == 0) { return M{{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}}; }
    if (n % 2 == 1) {
        return mul(pow(m, n - 1), m);
    } else {
        const auto pp = pow(m, n / 2);
        return mul(pp, pp);
    }
}
int main()
{
    ll N;
    std::cin >>  N;
    M m{{{1, 1, 0, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {0, 1, 0, 1}}};
    m = pow(m, N + 1);
    std::cout << m[2][1] << std::endl;
    return 0;
}
0