結果

問題 No.1595 The Final Digit
ユーザー trineutrontrineutron
提出日時 2021-07-09 21:49:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,300 KB
最終ジャッジ日時 2023-09-14 08:31:22
合計ジャッジ時間 1,415 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,204 KB
testcase_01 AC 16 ms
8,288 KB
testcase_02 AC 17 ms
8,276 KB
testcase_03 AC 16 ms
8,160 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 16 ms
7,808 KB
testcase_06 AC 17 ms
7,828 KB
testcase_07 AC 16 ms
7,796 KB
testcase_08 AC 16 ms
8,272 KB
testcase_09 AC 16 ms
8,300 KB
testcase_10 AC 16 ms
8,284 KB
testcase_11 AC 16 ms
8,228 KB
testcase_12 AC 17 ms
7,844 KB
testcase_13 AC 17 ms
7,840 KB
testcase_14 AC 18 ms
7,760 KB
testcase_15 AC 17 ms
7,888 KB
testcase_16 AC 16 ms
7,784 KB
testcase_17 AC 16 ms
8,224 KB
testcase_18 AC 17 ms
7,844 KB
testcase_19 AC 16 ms
7,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

p, q, r, k = map(int, input().split())
p %= 10
q %= 10
r %= 10
a = [p, q, r]

idx = {}
period = 0
for i in range(k - 3):
    x = 100*a[-3] + 10*a[-2] + a[-1]
    if x not in idx:
        idx[x] = i + 3
    else:
        period = i + 3 - idx[x]
        idx[x] = i + 3
        break
    a.append(sum(a[-3:]) % 10)
    if i == k - 4:
        print(a[-1])
        exit()

last = 0
for x, v in idx.items():
    if (k - 1 - v) % period == 0 and v > last:
        ans = (x // 100 + x // 10 + x) % 10
        last = v
print(ans)
0