結果
問題 | No.1595 The Final Digit |
ユーザー | H3PO4 |
提出日時 | 2023-07-31 08:43:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 468 ms / 2,000 ms |
コード長 | 476 bytes |
コンパイル時間 | 434 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,516 KB |
最終ジャッジ日時 | 2024-04-18 09:12:07 |
合計ジャッジ時間 | 11,702 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 437 ms
44,320 KB |
testcase_01 | AC | 444 ms
43,936 KB |
testcase_02 | AC | 440 ms
44,444 KB |
testcase_03 | AC | 435 ms
44,324 KB |
testcase_04 | AC | 433 ms
44,320 KB |
testcase_05 | AC | 448 ms
44,196 KB |
testcase_06 | AC | 429 ms
44,192 KB |
testcase_07 | AC | 436 ms
44,076 KB |
testcase_08 | AC | 467 ms
43,932 KB |
testcase_09 | AC | 452 ms
44,516 KB |
testcase_10 | AC | 457 ms
43,940 KB |
testcase_11 | AC | 441 ms
44,232 KB |
testcase_12 | AC | 440 ms
43,932 KB |
testcase_13 | AC | 436 ms
44,072 KB |
testcase_14 | AC | 438 ms
43,940 KB |
testcase_15 | AC | 430 ms
43,936 KB |
testcase_16 | AC | 444 ms
43,932 KB |
testcase_17 | AC | 449 ms
44,316 KB |
testcase_18 | AC | 468 ms
44,456 KB |
testcase_19 | AC | 448 ms
43,936 KB |
ソースコード
import numpy as np MOD = 10 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 *x, K = map(int, input().split()) M = np.array([[0, 0, 1], [1, 0, 1], [0, 1, 1]]) y = np.array(x) @ pow_matrix_mod(M, K - 3) % MOD print(y[-1])