結果

問題 No.1595 The Final Digit
ユーザー noriocnorioc
提出日時 2021-07-09 22:37:19
言語 Python3
(3.11.2 + numpy 1.24.2 + scipy 1.10.1)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 1,033 ms
実行使用メモリ 8,112 KB
最終ジャッジ日時 2023-02-02 00:38:11
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,884 KB
testcase_01 AC 17 ms
8,012 KB
testcase_02 AC 18 ms
8,040 KB
testcase_03 AC 17 ms
8,012 KB
testcase_04 AC 17 ms
7,964 KB
testcase_05 AC 17 ms
8,060 KB
testcase_06 AC 17 ms
8,008 KB
testcase_07 AC 18 ms
8,040 KB
testcase_08 AC 18 ms
7,872 KB
testcase_09 AC 17 ms
8,020 KB
testcase_10 AC 18 ms
8,004 KB
testcase_11 AC 17 ms
8,020 KB
testcase_12 AC 17 ms
7,872 KB
testcase_13 AC 18 ms
8,008 KB
testcase_14 AC 17 ms
8,016 KB
testcase_15 AC 17 ms
8,016 KB
testcase_16 AC 17 ms
8,112 KB
testcase_17 AC 18 ms
7,872 KB
testcase_18 AC 18 ms
8,064 KB
testcase_19 AC 17 ms
7,920 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