結果
問題 |
No.1810 RGB Biscuits
|
ユーザー |
![]() |
提出日時 | 2021-12-22 11:51:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 822 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 82,624 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-09-16 04:54:29 |
合計ジャッジ時間 | 3,079 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
import sys input = sys.stdin.readline mod = 10 ** 9 + 7 a,b = map(int, input().split()) n = int(input()) t = [int(input()) for _ in [0]*n] A = [[a,b], [1,0]] v = [[1], [1]] def matrix_prod(A,B): ac = len(A); al = len(A[0]) bc = len(B); bl = len(B[0]) res = [[0] * bl for _ in [0] * ac] for i in range(ac): for j in range(bl): for k in range(al): res[i][j] += A[i][k] * B[k][j] res[i][j] %= mod return res def matrix_exp(A,n): ac = len(A) res = [[0] * ac for _ in [0] * ac] for i in range(ac): res[i][i] = 1 while(n): if(n & 1): res = matrix_prod(A,res) A = matrix_prod(A,A) n >>= 1 return res for i in t: v1 = matrix_prod(matrix_exp(A, i // 2), v) v2 = matrix_prod(A, v1) if(i & 1): print((v1[0][0] + v1[1][0] + v2[0][0]) % mod) else: print((v1[0][0] + v1[1][0]) % mod)