結果

問題 No.1810 RGB Biscuits
ユーザー MasKoaTSMasKoaTS
提出日時 2021-12-22 11:51:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 78,496 KB
最終ジャッジ日時 2023-10-14 09:56:51
合計ジャッジ時間 4,920 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,136 KB
testcase_01 AC 87 ms
76,296 KB
testcase_02 AC 71 ms
71,164 KB
testcase_03 AC 92 ms
76,100 KB
testcase_04 AC 93 ms
76,288 KB
testcase_05 AC 168 ms
78,144 KB
testcase_06 AC 173 ms
78,496 KB
testcase_07 AC 172 ms
78,292 KB
testcase_08 AC 171 ms
78,376 KB
testcase_09 AC 170 ms
78,156 KB
testcase_10 AC 159 ms
77,968 KB
testcase_11 AC 111 ms
77,232 KB
testcase_12 AC 97 ms
76,768 KB
testcase_13 AC 95 ms
76,436 KB
testcase_14 AC 124 ms
77,704 KB
testcase_15 AC 100 ms
77,228 KB
testcase_16 AC 119 ms
78,392 KB
testcase_17 AC 152 ms
78,348 KB
testcase_18 AC 153 ms
78,220 KB
testcase_19 AC 90 ms
76,500 KB
testcase_20 AC 74 ms
71,376 KB
testcase_21 AC 123 ms
78,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0