結果

問題 No.147 試験監督(2)
ユーザー finefine
提出日時 2017-07-16 02:03:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 174,032 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 21:55:52
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat& A, mat& B) {
	mat C(A.size(), vec(B[0].size(), 0));
	for (int i = 0; i < A.size(); i++) {
		for (int k = 0; k < B.size(); k++) {
			for (int j = 0; j < B[0].size(); j++) {
				(C[i][j] += A[i][k] * B[k][j] % MOD) %= MOD; 
			}
		}
	}
	return C;
}

mat pow(mat A, ll n) {
	mat B(A.size(), vec(A.size(), 0));
	for (int i = 0; i < A.size(); i++) {
		B[i][i] = 1;
	}
	while (n > 0) {
		if (n & 1) B = mul(B, A);
		A = mul(A, A);
		n >>= 1;
	}
	return B;
}

ll bignum_mod(string d) {
	ll res = 0;
	for (char c : d) {
		res = (res * 10 + c - '0') % (MOD - 1);
	}
	return res;
}

ll modpow(ll x, ll n) {
	if (x == 0) return 0;
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans = 1;
	mat A = {{1, 1}, {1, 0}};
	mat B = {{3}, {2}};
	for (int i = 0; i < n; i++) {
		ll c;
		string d;
		cin >> c >> d;
		ll m = bignum_mod(d);
		mat C = pow(A, c - 1);
		C = mul(C, B);
		(ans *= modpow(C[1][0], m)) %= MOD;
	}
	cout << ans << endl;
	return 0;
}
0