結果

問題 No.147 試験監督(2)
ユーザー pekempeypekempey
提出日時 2015-08-21 12:28:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 156,088 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 14:18:44
合計ジャッジ時間 6,316 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

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

mat matmul(mat A, mat B) {
	mat res(A.size(), vec(B[0].size()));
	rep (i, A.size()) rep (k, B.size()) rep (j, B[0].size()) {
		(res[i][j] += A[i][k] * B[k][j]) %= mod;
	}
	return res;
}

mat identity(int n) {
	mat res(n, vec(n));
	rep (i, n) res[i][i] = 1;
	return res;
}

mat matpow(mat A, ll b) {
	mat res = identity(A.size());
	while (b) {
		if (b & 1) res = matmul(res, A);
		A = matmul(A, A);
		b >>= 1;
	}
	return res;
}

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) {
	ll B = bigmodulo(b, mod - 1);
	return modpow(a, B);	
}

int main() {
	mat A{{1, 1}, {1, 0}};

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

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

	return 0;
}
0