結果

問題 No.147 試験監督(2)
ユーザー chocoruskchocorusk
提出日時 2019-07-08 19:13:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,194 ms / 2,000 ms
コード長 1,994 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 109,872 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 12:51:28
合計ジャッジ時間 6,466 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
vector<vector<ll>> matrixmul(int l, int m, int n, vector<vector<ll>> a, vector<vector<ll>> b){
	vector<vector<ll>> c;
	for(int i=0; i<l; i++){
		vector<ll> v;
		for(int j=0; j<n; j++){
			ll x=0;
			for(int k=0; k<m; k++){
				x+=(a[i][k]*b[k][j]);
				x%=MOD;
			}
			v.push_back(x);
		}
		c.push_back(v);
	}
	return c;
}
vector<vector<ll>> matrixpow(int n, vector<vector<ll>> a, ll k){
	vector<vector<ll>> ap=a, ans;
	for(int i=0; i<n; i++){
		vector<ll> v;
		for(int j=0; j<n; j++){
			if(i==j){
				v.push_back(1);
			}else{
				v.push_back(0);
			}
		}
		ans.push_back(v);
	}
	while(k){
		if(k&1) ans=matrixmul(n, n, n, ap, ans);
		ap=matrixmul(n, n, n, ap, ap);
		k>>=1;
	}
	return ans;
}
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll solve(ll c){
    vector<vector<ll>> a(2, vector<ll>(2));
    a[0][0]=a[0][1]=a[1][0]=1;
    vector<vector<ll>> ap=matrixpow(2, a, c+2);
    return ap[1][0];
}
ll mod(string d){
    ll p=1, ret=0;
    for(int i=d.size()-1; i>=0; i--){
        (ret+=p*(d[i]-'0'))%=(MOD-1);
        (p*=10)%=(MOD-1);
    }
    return ret;
}
int main()
{
    int n; cin>>n;
    ll ans=1;
    for(int i=0; i<n; i++){
        ll c;
        string d;
        cin>>c>>d;
        ll x=solve(c);
        if(x==0){
            cout<<0<<endl;
            return 0;
        }
        (ans*=powmod(x, mod(d)))%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
0