結果

問題 No.1595 The Final Digit
ユーザー noriocnorioc
提出日時 2021-07-09 22:37:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 8,664 KB
最終ジャッジ日時 2023-09-14 09:56:00
合計ジャッジ時間 1,486 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,664 KB
testcase_01 AC 18 ms
8,660 KB
testcase_02 AC 19 ms
8,508 KB
testcase_03 AC 19 ms
8,512 KB
testcase_04 AC 19 ms
8,436 KB
testcase_05 AC 19 ms
8,532 KB
testcase_06 AC 19 ms
8,488 KB
testcase_07 AC 18 ms
8,492 KB
testcase_08 AC 18 ms
8,568 KB
testcase_09 AC 18 ms
8,488 KB
testcase_10 AC 18 ms
8,480 KB
testcase_11 AC 19 ms
8,560 KB
testcase_12 AC 18 ms
8,588 KB
testcase_13 AC 18 ms
8,560 KB
testcase_14 AC 19 ms
8,512 KB
testcase_15 AC 19 ms
8,508 KB
testcase_16 AC 18 ms
8,516 KB
testcase_17 AC 19 ms
8,516 KB
testcase_18 AC 18 ms
8,500 KB
testcase_19 AC 18 ms
8,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
from itertools import count

p, q, r, K = map(int, input().split())

p %= 10
q %= 10
r %= 10
memo = collections.defaultdict(int)
memo[p, q, r] = 3
a = [p, q, r]
for i in count(4):
    x = (a[-1] + a[-2] + a[-3]) % 10
    a.append(x)
    if i == K:
        print(a[-1])
        break

    key = (a[-3], a[-2], a[-1])
    if key in memo: # found cycle
        m = memo[key]
        t = K - (m - 1)
        d = i - m
        index = t % (i - m)
        print(a[index + 1])
        # print(f'{index=}')
        # print(f'{a=}')
        break

    memo[key] = i
    if i == K:
        print(a[-1])
        break
0