結果

問題 No.1595 The Final Digit
コンテスト
ユーザー norioc
提出日時 2021-07-09 22:37:19
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 24 ms / 2,000 ms
+ 757µs
コード長 626 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 62 ms
コンパイル使用メモリ 15,104 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2026-10-13 23:07:27
合計ジャッジ時間 2,079 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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