結果
| 問題 |
No.1073 無限すごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-17 20:20:00 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 509 ms / 2,000 ms |
| コード長 | 503 bytes |
| コンパイル時間 | 115 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 44,596 KB |
| 最終ジャッジ日時 | 2024-06-25 10:14:01 |
| 合計ジャッジ時間 | 19,414 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
import numpy as np
N = int(input())
MOD = 10 ** 9 + 7
modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)
def pow_matrix_mod(x, n, mod=MOD):
x = x.astype(object)
if not n:
return np.eye(len(x), dtype=object)
if n % 2 == 0:
return pow_matrix_mod(x @ x % mod, n // 2) % mod
else:
return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod
A = np.zeros((6, 6), dtype=int)
A[0] = modinv(6)
for i in range(5):
A[i + 1, i] = 1
print(pow_matrix_mod(A, N)[0, 0])