結果

問題 No.793 うし数列 2
ユーザー koi_kotyakoi_kotya
提出日時 2019-02-22 21:38:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 171,088 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 16:38:29
合計ジャッジ時間 2,858 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<vector<ll>> prod(vector<vector<ll>>& a, vector<vector<ll>>& b, ll mod) {
    vector<vector<ll>> ret(a.size(),vector<ll>(b[0].size(),0));
    for (int i = 0;i < a.size();++i) for (int j = 0;j < b[0].size();++j) for (int k = 0;k < a[0].size();++k) {
        ret[i][j] += a[i][k]*b[k][j];
        ret[i][j] %= mod;
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    vector<vector<ll>> e(1,vector<ll>(2,1)),c(2,vector<ll>(2,0));
    c[0][0] = 10;
    c[1][0] = 3;
    c[1][1] = 1;
    e[0][0] = 13;
    n--;
    while (n) {
        if (n&1) e = prod(e,c,mod);
        c = prod(c,c,mod);
        n >>= 1;
    }
    cout << e[0][0] << endl;
    return 0;
}
0