結果

問題 No.147 試験監督(2)
ユーザー commy
提出日時 2020-05-01 01:40:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 936 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 78,176 KB
最終ジャッジ日時 2024-12-21 10:05:17
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
mod = 1000000007

def matrixmul(a, b):
    res = [0, 0, 0, 0]
    for i in range(2):
        for j in range(2):
            for k in range(2):
                res[2 * i + j] += a[2 * i + k] * b[2 * k + j]
            res[2 * i + j] %= mod
    return res

def powmatrix(matrix, p):
    ans = [1, 0, 0, 1]
    while p > 0:
        if p % 2 == 1:
            ans = matrixmul(ans, matrix)
        matrix = matrixmul(matrix, matrix)
        p >>= 1
    return ans

matrix = [1, 1, 1, 0]
ans = 1

for i in range(n):
    c, d = map(int, input().split())
    res = powmatrix(matrix, c + 1)[0]
    d %= (mod - 1)
    if d == 0:
        d = mod - 1
    ans *= pow(res, d, mod)
    ans %= mod

print(ans)
0