結果

問題 No.1073 無限すごろく
ユーザー anagohirameanagohirame
提出日時 2020-06-05 21:49:37
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 76,732 KB
最終ジャッジ日時 2023-08-22 15:04:49
合計ジャッジ時間 4,312 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,468 KB
testcase_01 AC 71 ms
71,368 KB
testcase_02 AC 80 ms
75,688 KB
testcase_03 AC 71 ms
71,504 KB
testcase_04 AC 71 ms
71,224 KB
testcase_05 AC 70 ms
71,412 KB
testcase_06 AC 73 ms
71,320 KB
testcase_07 AC 72 ms
71,320 KB
testcase_08 AC 70 ms
71,252 KB
testcase_09 AC 72 ms
71,340 KB
testcase_10 AC 74 ms
75,496 KB
testcase_11 AC 74 ms
75,548 KB
testcase_12 AC 77 ms
75,520 KB
testcase_13 AC 79 ms
75,896 KB
testcase_14 AC 79 ms
75,876 KB
testcase_15 AC 81 ms
75,568 KB
testcase_16 AC 79 ms
75,808 KB
testcase_17 AC 80 ms
75,616 KB
testcase_18 AC 82 ms
75,500 KB
testcase_19 AC 82 ms
75,796 KB
testcase_20 AC 82 ms
75,660 KB
testcase_21 AC 85 ms
76,560 KB
testcase_22 AC 81 ms
75,724 KB
testcase_23 AC 87 ms
76,512 KB
testcase_24 AC 87 ms
76,504 KB
testcase_25 AC 87 ms
76,288 KB
testcase_26 AC 87 ms
76,680 KB
testcase_27 AC 85 ms
76,624 KB
testcase_28 AC 90 ms
76,648 KB
testcase_29 AC 88 ms
76,576 KB
testcase_30 AC 89 ms
76,648 KB
testcase_31 AC 90 ms
76,524 KB
testcase_32 AC 90 ms
76,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9+7

def mat_dot(one, two, mod):
	return [[sum([(one[i][k]*two[k][j])%mod for k in range(max(len(two), len(one[0])))])%mod for j in range(len(two[0]))] for i in range(len(one))]

def mat_pow(mat, exp, mod):
	size = len(mat)
	res = [[0 for _ in range(size)] for _ in range(size)]
	for i in range(size):
		res[i][i] = 1
	cnt = 0
	while (1<<cnt) <= exp:
		if (exp>>cnt)&1:
			res = mat_dot(res, mat, mod)
		mat = mat_dot(mat, mat, mod)
		cnt += 1
	return res

n = int(input())
s = 166666668

p = [1, s]
for _ in range(4):
	p.append((p[-1] * 7 * s) % MOD)

if n < 6:
	print(p[n])

else:
	mat = [
	[0, 1, 0, 0, 0, 0], 
	[0, 0, 1, 0, 0, 0], 
	[0, 0, 0, 1, 0, 0], 
	[0, 0, 0, 0, 1, 0], 
	[0, 0, 0, 0, 0, 1], 
	[s, s, s, s, s, s]
	]

	res = mat_pow(mat, n-5, MOD)
	ans = 0
	for i in range(6):
		ans += p[i] * res[5][i]
		ans %= MOD

	print(ans)
0