結果

問題 No.147 試験監督(2)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-09-07 23:32:41
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 887 bytes
コンパイル時間 2,439 ms
コンパイル使用メモリ 77,608 KB
実行使用メモリ 99,340 KB
最終ジャッジ日時 2023-09-26 10:03:11
合計ジャッジ時間 8,123 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
mod = int(1e9) + 7

def matmul(A, B):
    p, q = len(A[0]), len(B)
    if p != q:
        print 'len(A[0])={} len(B)={}'.format(p, q)
        return None
    rows, cols, times = len(A), len(B[0]), len(A[0])
    res = [[0 for _ in xrange(cols)] for _ in xrange(rows)]
    for r in xrange(rows):
        for c in xrange(cols):
            res[r][c] = sum(A[r][i]*B[i][c] for i in xrange(times)) % mod
    return res

def matpow(A, n):
    sz = len(A)
    res = [[1 if i==j else 0 for j in xrange(sz)] for i in xrange(sz)]
    while n > 0:
        if n & 1:
            res = matmul(res, A)
        A = matmul(A, A)
        n >>= 1
    return res

n = int(raw_input())
res = 1
for i in xrange(n):
    c, d = map(int, raw_input().split())
    x = matpow([[1, 1], [1, 0]], c+1)[0][0]
    if d > mod - 1:
        d %= (mod - 1)
    res = res * pow(x, d, mod) % mod
print res
0