結果

問題 No.1595 The Final Digit
ユーザー kamomekamome
提出日時 2021-07-10 16:56:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 29,732 KB
最終ジャッジ日時 2023-09-14 19:42:11
合計ジャッジ時間 6,609 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,612 KB
testcase_01 AC 130 ms
29,568 KB
testcase_02 AC 129 ms
29,668 KB
testcase_03 AC 128 ms
29,656 KB
testcase_04 AC 126 ms
29,648 KB
testcase_05 AC 127 ms
29,668 KB
testcase_06 AC 129 ms
29,632 KB
testcase_07 AC 130 ms
29,660 KB
testcase_08 AC 127 ms
29,516 KB
testcase_09 AC 126 ms
29,576 KB
testcase_10 AC 126 ms
29,636 KB
testcase_11 AC 127 ms
29,732 KB
testcase_12 AC 128 ms
29,640 KB
testcase_13 AC 130 ms
29,640 KB
testcase_14 AC 132 ms
29,692 KB
testcase_15 AC 135 ms
29,588 KB
testcase_16 AC 132 ms
29,624 KB
testcase_17 AC 127 ms
29,632 KB
testcase_18 AC 126 ms
29,648 KB
testcase_19 AC 130 ms
29,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
p, q, r, K = map(int, input().split())
mat = np.array([[1, 1, 1], [1, 0, 0], [0, 1, 0]], dtype=np.int32)
ans = np.array(np.eye(3), dtype=np.int32)
K -= 3
while K > 0:
    if K & 1:
        ans = np.dot(mat, ans)
    mat = np.dot(mat, mat)

    for i in range(3):
        for j in range(3):
            ans[i][j] %= 10
            mat[i][j] %= 10
    K >>= 1

x = ans[0][0]*r+ans[0][1]*q+ans[0][2]*p
print(x % 10)
0