結果

問題 No.147 試験監督(2)
ユーザー pekempeypekempey
提出日時 2015-08-21 13:17:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 146,060 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 14:19:12
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define asn(a, b, c) fill_n(&(b), sizeof(a) / sizeof(b), c)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

const int dim = 2;
typedef ll mat[dim][dim];
mat M0, M1, M2, M3;

void matmul(mat A, mat B, mat res) {
	memset(M0, 0, sizeof(M0));
	rep (i, 2) rep (k, 2) rep (j, 2) {
		(M0[i][j] += A[i][k] * B[k][j]) %= mod;
	}
	memcpy(res, M0, sizeof(M0));
}

void matpow(mat A, ll b, mat res) {
	memcpy(M1, A, sizeof(M1));
	rep (i, dim) rep (j, dim) M2[i][j] = i == j;
	while (b > 0) {
		if (b & 1) matmul(M1, M2, M2);
		matmul(M1, M1, M1);
		b >>= 1;
	}
	memcpy(res, M2, sizeof(M2));
}

ll modpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1) (res *= a) %= mod;
		(a *= a) %= mod;
		b >>= 1;
	}
	return res;
}

ll bigmodulo(string &s, ll m) {
	ll res = 0;
	for (char d : s) {
		res *= 10;
		res += d - '0';
		res %= m;		
	}
	return res;
}

ll bigmodpow(ll a, string &b) {
	if (a == 0) return 0;
	ll B = bigmodulo(b, mod - 1);
	return modpow(a, B);	
}

int main() {
	int N;
	cin >> N;
	ll ans = 1;
	rep (i, N) {
		ll C;
		string D;
		cin >> C >> D;

		mat A = {{1, 1}, {1, 0}};
		mat An;
		matpow(A, C, An);
		ll m = (An[0][0] + An[1][0]) % mod;
		ans *= bigmodpow(m, D);
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}
0