結果
| 問題 | No.1595 The Final Digit |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2021-07-09 22:37:19 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 626 bytes |
| コンパイル時間 | 213 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-01 17:20:12 |
| 合計ジャッジ時間 | 1,636 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
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
norioc