結果

問題 No.147 試験監督(2)
ユーザー dnishdnish
提出日時 2018-07-02 09:37:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,820 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 173,464 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 16:51:44
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a,b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,C;
//A*B
mat mul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size(),0));
    REP(i, 0, A.size())
        REP(k, 0, B.size())
            REP(j, 0, B[0].size())
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
    return C;
}

//A^n
mat mat_pow(mat A, long long n){
    mat B(A.size(), vec(A.size(), 0));
    REP(i, 0, A.size()) B[i][i] = 1;
    while(n > 0){
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}
long long fast_power(long long a, long long b) {
    long long ret = 1;
    // aが負の場合
    if (a < 0) {
        a = -a;
        if (b % 2 == 1) ret = -1;
    }
    // 累乗計算
    while (b>0) {
        if (b & 1) {
            ret *= a;
        }
        a *= a;
        a %= mod;
        ret %= mod;
        b >>= 1;
    }
    return ret;
}

string D;
int main(){
    cin>>N;
    ll ans=1;
    mat A(2, vec(2,0));
    A[0][0] = A[1][0] = A[0][1] = 1;
    A[1][1] = 0;
    REP(i,0,N){
        cin>>C>>D;

        mat AA = mat_pow(A, C+1);
        mat B(2, vec(1,0));
        B[0][0] = 1, B[1][0] = 0;
        mat F = mul(AA, B);
        ll d=0;
        REP(i,0,D.size()){
            d *= 10;
            d += D[i] - '0';
            d %= mod;
        }
        ans *= fast_power(F[0][0] , d) % mod;
        ans %= mod;
    }
    p(ans);
    return 0;
}
0