結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-21 13:17:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 222 ms / 2,000 ms |
| コード長 | 1,476 bytes |
| コンパイル時間 | 1,298 ms |
| コンパイル使用メモリ | 159,860 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 11:15:53 |
| 合計ジャッジ時間 | 2,875 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#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;
}