結果

問題 No.1810 RGB Biscuits
ユーザー MasKoaTS
提出日時 2021-09-17 22:44:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-10-01 07:35:39
合計ジャッジ時間 3,663 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7

a,b = map(int,input().split())
n = int(input())
t = []
for _ in range(n):
	t.append(int(input()))

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