結果

問題 No.147 試験監督(2)
ユーザー sugim48sugim48
提出日時 2015-02-09 01:52:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 637 ms / 2,000 ms
コード長 1,918 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 95,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 15:59:06
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

vector< vector<ll> > matmul(vector< vector<ll> >& A, vector< vector<ll> >& B) {
	int n = A.size();
	vector< vector<ll> > C(n, vector<ll>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
	return C;
}

vector< vector<ll> > matpow(vector< vector<ll> > A, ll x) {
	int n = A.size();
	vector< vector<ll> > B(n, vector<ll>(n));
	for (int i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {
		if (x % 2) B = matmul(B, A);
		x /= 2;
		A = matmul(A, A);
	}
	return B;
}

int pow_mod(ll x, ll n, int m) {
	if (n == 0) return 0;
	ll res = 1;
	for (; n > 0; n >>= 1) {
		if (n & 1) res = (res * x) % m;
		x = (x * x) % m;
	}
	return res;
}

char D[202];

int main() {
	vector< vector<ll> > A(2, vector<ll>(2));
	A[0][0] = 1; A[0][1] = 1;
	A[1][0] = 1; A[1][1] = 0;
	vector<ll> a(201);
	a[0] = 1;
	for (int i = 1; i <= 200; i++)
		a[i] = a[i - 1] * 10 % (MOD - 1);
	int N; cin >> N;
	ll ans = 1;
	while (N--) {
		ll C; scanf("%lld%s", &C, D);
		int d = strlen(D);
		ll x = matpow(A, C + 1)[0][0];
		ll y = 0;
		for (int i = 0; i < d; i++)
			y = (y + a[d - i - 1] * (D[i] - '0')) % (MOD - 1);
		ans = ans * pow_mod(x, y, MOD) % MOD;
	}
	cout << ans << endl;
}
0