結果

問題 No.1595 The Final Digit
ユーザー 回転
提出日時 2025-10-13 22:02:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 55,680 KB
最終ジャッジ日時 2025-10-13 22:02:54
合計ジャッジ時間 2,351 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
p,q,r,K = list(map(int,input().split()))

now = (p+q+r) % 10
A = [p,q,r]
d = defaultdict(int)
for i in range(4,K+1):
    now = (A[-1] + A[-2] + A[-3]) % 10
    A.append(now)
    if((A[-1]%10, A[-2]%10, A[-3]%10) not in d):
        d[(A[-1]%10, A[-2]%10, A[-3]%10)] = i
    else:
        loop_len = i - d[(A[-1]%10, A[-2]%10, A[-3]%10)]
        nokori = (K - i) % loop_len
        for _ in range(nokori):
            now = (A[-1] + A[-2] + A[-3]) % 10
            A.append(now)
        print(now)
        exit()
print(now)
0