結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-07-16 02:02:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,214 bytes |
| コンパイル時間 | 1,949 ms |
| コンパイル使用メモリ | 176,652 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 02:44:37 |
| 合計ジャッジ時間 | 4,864 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 1 |
ソースコード
#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) {
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;
}