結果

問題 No.1810 RGB Biscuits
ユーザー MasKoaTSMasKoaTS
提出日時 2021-09-17 22:44:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 415 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-04-08 14:58:52
合計ジャッジ時間 4,699 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,112 KB
testcase_01 AC 32 ms
10,112 KB
testcase_02 AC 33 ms
10,112 KB
testcase_03 AC 35 ms
10,112 KB
testcase_04 AC 34 ms
10,112 KB
testcase_05 AC 379 ms
10,240 KB
testcase_06 AC 415 ms
10,240 KB
testcase_07 AC 411 ms
10,240 KB
testcase_08 AC 415 ms
10,240 KB
testcase_09 AC 411 ms
10,240 KB
testcase_10 AC 261 ms
10,240 KB
testcase_11 AC 37 ms
10,240 KB
testcase_12 AC 38 ms
10,112 KB
testcase_13 AC 37 ms
10,112 KB
testcase_14 AC 90 ms
10,240 KB
testcase_15 AC 38 ms
10,112 KB
testcase_16 AC 48 ms
10,112 KB
testcase_17 AC 209 ms
10,240 KB
testcase_18 AC 213 ms
10,240 KB
testcase_19 AC 33 ms
10,112 KB
testcase_20 AC 31 ms
10,112 KB
testcase_21 AC 70 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

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