結果
| 問題 |
No.1595 The Final Digit
|
| ユーザー |
norioc
|
| 提出日時 | 2025-05-27 10:15:35 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 413 ms / 2,000 ms |
| コード長 | 510 bytes |
| コンパイル時間 | 575 ms |
| コンパイル使用メモリ | 12,032 KB |
| 実行使用メモリ | 32,052 KB |
| 最終ジャッジ日時 | 2025-05-27 10:15:48 |
| 合計ジャッジ時間 | 11,735 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
import numpy as np
def mat_power(m: np.ndarray, n: int, mod: int) -> np.ndarray:
if n == 0: return np.identity(len(m), dtype=object)
res = mat_power(m, n // 2, mod)
res = res @ res % mod
if n % 2 == 1:
res = res @ m % mod
return res
MOD = 10
P, Q, R, K = map(int, input().split())
P %= 10
Q %= 10
R %= 10
m = np.array(
[[1, 1, 1],
[1, 0, 0],
[0, 1, 0]])
a = np.array(
[[R],
[Q],
[P]])
t = mat_power(m, K-3, MOD) @ a
ans = t[0, 0] % MOD
print(ans)
norioc