結果

問題 No.1810 RGB Biscuits
ユーザー MasKoaTS
提出日時 2022-01-12 21:51:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 77,336 KB
最終ジャッジ日時 2024-11-15 14:07:15
合計ジャッジ時間 3,364 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7

a,b = map(int,input().split())
n = int(input())

if not(1 <= a <= 10 ** 9 and 1 <= b <= 10 ** 9 and 1 <= n <= 1000):
    exit(1)

t = []
for _ in range(n):
	t.append(int(input()))
	if not(0 <= t[-1] <= 10 ** 18):
	    exit(1)

def matrix_prod(A,B):
	res = [[0]*2 for _ in range(2)]
	for i in range(2):
		for j in range(2):
			for k in range(2):
				res[i][j] += A[i][k] * B[k][j]
				res[i][j] %= mod
	return res

def matrix_exp(A,n):
	res = [[1,0],[0,1]]
	while(n):
		if(n & 1):
			res = matrix_prod(A,res)
		A = matrix_prod(A,A)
		n >>= 1
	return res

def P_convertion(A,v):
	res = [0]*2
	for i in range(2):
		for j in range(2):
			res[i] += A[i][j] * v[j]
			res[i] %= mod
	return res

A = [[a,b],[1,0]]
v = [1,1]
for i in t:
	d = i // 2
	r = i % 2
	v1 = P_convertion(matrix_exp(A,d),v)
	v2 = P_convertion(A,v1)
	if(r == 1):
		print((v1[0] + v1[1] + v2[0]) % mod)
	else:
		print((v1[0] + v1[1]) % mod)
		
0