結果

問題 No.891 隣接3項間の漸化式
ユーザー ForestedForested
提出日時 2020-05-26 13:40:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,014 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 99,896 KB
実行使用メモリ 814,592 KB
最終ジャッジ日時 2024-04-21 04:15:55
合計ジャッジ時間 3,577 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

constexpr int mod = 1000000007;
using mat = vector<vector<int>>;

mat matrix_mul(mat &A, mat &B) {
    mat C(A.size(), vector<int>(B[0].size(), 0));
    rep(i, A.size()) rep(j, B[0].size()) rep(k, B.size()) {
        C[i][j] += (long long)A[i][k] * B[k][j] % mod;
        C[i][j] %= mod;
    }
    return C;
}

mat matrix_pow(mat &A, int n) {
    if (n == 1) return A;
    mat B = matrix_pow(A, n / 2);
    mat C = matrix_mul(B, B);
    if (n % 2) return matrix_mul(C, A);
    return matrix_mul(B, B);
}

int main() {
    int a, b, n;
    cin >> a >> b >> n;
    
    mat A = {{a, b}, {1, 0}};
    mat B = {{1}, {0}};
    mat C = matrix_pow(A, n);
    mat ans = matrix_mul(C, B);
    cout << ans[1][0] << endl;
    return 0;
}
0