結果

問題 No.147 試験監督(2)
ユーザー h_nosonh_noson
提出日時 2016-04-19 11:44:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 767 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 73,332 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 03:43:22
合計ジャッジ時間 4,287 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 761 ms
6,816 KB
testcase_01 AC 757 ms
6,944 KB
testcase_02 AC 767 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
#define MOD 1000000007

typedef long long ll;

vector<vector<ll>> ini(2,vector<ll>(2));

vector<vector<ll>> mult(vector<vector<ll>> a, vector<vector<ll>> b) {
    int i, j, k;
    vector<vector<ll>> c(2,vector<ll>(2));
    rep (i,2) rep (j,2) rep (k,2) {
        c[i][j] += a[i][k] * b[k][j];
        c[i][j] %= MOD;
    }
    return c;
}

ll solve(ll c) {
    int i, j;
    vector<vector<ll>> mat(2,vector<ll>(2));
    auto x = ini;
    mat[0][0] = mat[1][1] = 1;
    mat[0][1] = mat[1][0] = 0;
    while (c > 0) {
        if (c % 2)
            mat = mult(x,mat);
        x = mult(x,x);
        c /= 2;
    }
    return (mat[1][0] * 2 + mat[1][1]) % MOD;
}

ll power(ll x, ll n) {
    ll ret = 1;
    if (x == 0)
        return 0;
    while (n > 0) {
        if (n % 2) {
            ret *= x;
            ret %= MOD;
        }
        x *= x;
        x %= MOD;
        n /= 2;
    }
    return ret;
}

int main() {
    int i, n;
    ll ans;
    cin >> n;
    ans = 1;
    ini[0][0] = ini[0][1] = ini[1][0] = 1;
    ini[1][1] = 0;
    rep (i,n) {
        ll c, d;
        string sd;
        cin >> c >> sd;
        d = 0;
        for (auto chr : sd) 
            d = (d * 10 + chr - '0') % (MOD-1);
        ans *= power(solve(c),d) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0