結果

問題 No.1595 The Final Digit
ユーザー RyoSciRyoSci
提出日時 2021-07-09 23:03:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 599 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 71,544 KB
最終ジャッジ日時 2023-09-14 10:36:21
合計ジャッジ時間 2,786 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,424 KB
testcase_01 AC 72 ms
71,280 KB
testcase_02 AC 72 ms
71,424 KB
testcase_03 AC 72 ms
71,384 KB
testcase_04 WA -
testcase_05 AC 71 ms
71,248 KB
testcase_06 AC 73 ms
71,544 KB
testcase_07 AC 70 ms
71,392 KB
testcase_08 AC 71 ms
71,292 KB
testcase_09 AC 72 ms
71,204 KB
testcase_10 AC 72 ms
71,208 KB
testcase_11 AC 73 ms
71,292 KB
testcase_12 AC 72 ms
71,284 KB
testcase_13 AC 72 ms
71,296 KB
testcase_14 AC 73 ms
71,516 KB
testcase_15 AC 74 ms
71,388 KB
testcase_16 AC 73 ms
71,308 KB
testcase_17 AC 71 ms
71,280 KB
testcase_18 AC 72 ms
71,496 KB
testcase_19 AC 72 ms
71,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

p, q, r, k = map(int, input().split())
p_, q_, r_ = p, q, r
memo = [[[-1 for i in range(10)] for j in range(10)] for k in range(10)]


flag = False
for i in range(k+1):
    r, q, p = r % 10, q % 10, p % 10
    if memo[p][q][r] == -1:
        memo[p][q][r] = i
    else:
        start = memo[p][q][r]
        end = i
        cycle = end-start
        flag = True
        break
    a = p+q+r
    a %= 10
    r, q, p = a, r, q

if flag:
    if k-start >= cycle:
        k = start+(k-start) % cycle

p, q, r = p_, q_, r_
for i in range(4, k+1):
    a = p+q+r
    a %= 10
    r, q, p = a, r, q

print(a)
0