結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2015-04-04 14:53:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,361 bytes |
| コンパイル時間 | 1,452 ms |
| コンパイル使用メモリ | 165,740 KB |
| 実行使用メモリ | 13,824 KB |
| 最終ジャッジ日時 | 2024-07-04 01:51:15 |
| 合計ジャッジ時間 | 8,256 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 3 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll MM = MOD-1;
template<int R, int C, ll mod>
class Mat {
public:
Mat() : mat(R, vector<ll>(C)) {}
Mat<R, C, mod>& operator=(const Mat<R, C, mod>& rhs) {
for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) {
mat[i][j] = rhs[i][j];
}
return *this;
}
vector<ll>& operator[](int r) {return mat[r];}
const vector<ll> operator[](int r) const {return mat[r];}
Mat<R, C, mod>& operator+=(const Mat<R, C, mod> rhs) {
for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) {
mat[i][j] += rhs.mat[i][j];
if (mat[i][j] >= mod) mat[i][j] %= mod;
}
return (*this);
}
Mat<R, C, mod>& operator-=(const Mat<R, C, mod> rhs) {
for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) {
mat[i][j] -= rhs.mat[i][j];
mat[i][j] %= mod;
if (mat[i][j] < 0) mat[i][j] += mod;
}
return (*this);
}
const Mat<R, C, mod> operator+(const Mat<R, C, mod> rhs) const {
Mat<R, C, mod> ret = (*this);
ret += rhs;
return ret;
}
const Mat<R, C, mod> operator-(const Mat<R, C, mod> rhs) const {
Mat<R, C, mod> ret = (*this);
ret -= rhs;
return ret;
}
const Mat<R, R, mod> operator*(const Mat<C, R, mod> rhs) const {
Mat<R, R, mod> ret;
for (int i = 0; i < R; i++) {
for (int k = 0; k < C; k++) {
for (int j = 0; j < R; j++) {
ret[i][j] += (*this)[i][k] * rhs[k][j];
if (ret[i][j] >= mod) ret[i][j] %= mod;
}
}
}
return ret;
}
void print() const {
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cout << mat[i][j] << "\t";
}
cout << endl;
}
}
private:
vector<vector<ll> > mat;
};
template<int R, ll mod>
Mat<R, R, mod> matrixPow(Mat<R, R, mod> a, ll N) {
Mat<R, R, mod> ret;
for (int i = 0; i < R; i++) ret[i][i] = 1;
for (int i = 0; N>0; i++) {
if ((N>>i)&1) {
ret = ret*a;
N -= (1<<i);
}
a = a*a;
}
return ret;
}
typedef Mat<2, 2, MOD> Mat2x2;
ll getMod(const string& s) {
int n = s.size();
ll ans = 0;
for (int i = 0; i < n; i++) {
ans *= 10;
ans += (s[i]-'0');
ans %= MM;
}
return ans;
}
// x^p
ll powmod(ll x, ll p, ll m = MOD) {
if (x == 0) return 0;
if (p == 0) return 1;
if (p == 1) return x;
if (p % 2 == 0) {
ll tmp = powmod(x, p/2, m);
return (tmp*tmp)%m;
} else {
ll tmp = powmod(x, p-1, m);
return (tmp*x)%m;
}
}
int main() {
int N;
cin >> N;
ll ans = 1;
Mat2x2 a;
a[0][1] = a[1][0] = a[1][1] = 1;
while (N--) {
ll C;
string D;
cin >> C >> D;
ll d = getMod(D);
Mat2x2 b = matrixPow(a, C-1);
ll tmp = b[1][0] + b[1][1] * 2;
tmp %= MOD;
ans *= powmod(tmp, d);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
mayoko_