結果

問題 No.1595 The Final Digit
ユーザー ygd.ygd.
提出日時 2021-07-31 17:09:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 76,344 KB
最終ジャッジ日時 2023-10-14 15:01:09
合計ジャッジ時間 3,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,628 KB
testcase_01 AC 91 ms
76,056 KB
testcase_02 AC 88 ms
71,416 KB
testcase_03 AC 91 ms
71,568 KB
testcase_04 AC 89 ms
71,428 KB
testcase_05 AC 88 ms
71,512 KB
testcase_06 AC 87 ms
71,644 KB
testcase_07 AC 88 ms
71,572 KB
testcase_08 AC 88 ms
71,708 KB
testcase_09 AC 92 ms
76,180 KB
testcase_10 AC 90 ms
71,632 KB
testcase_11 AC 90 ms
76,056 KB
testcase_12 AC 90 ms
76,176 KB
testcase_13 AC 87 ms
71,608 KB
testcase_14 AC 90 ms
76,344 KB
testcase_15 AC 94 ms
76,344 KB
testcase_16 AC 91 ms
71,396 KB
testcase_17 AC 88 ms
71,456 KB
testcase_18 AC 89 ms
71,652 KB
testcase_19 AC 90 ms
71,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict 

def main():
    p,q,r,k = map(int,input().split())
    A = [p%10,q%10,r%10]
    dic = defaultdict(int)
    dic[tuple(A)] = 1 #1スタート
    dic1 = defaultdict(int)
    num = 2
    while True:
        val = A[-1] + A[-2] + A[-3]
        val %= 10
        nxt = (A[-2], A[-1], val)
        A.append(val)
        if nxt in dic:
            loop_start = dic[nxt]
            loop_last = num - 1 
            break
        else:
            dic[nxt] = num
            num += 1
    #print(dic,loop_start,loop_last)
    loop_len = loop_last - loop_start + 1 
    if k <= len(A):
        print(A[k-1]);exit()
    amari = loop_start - 1
    idx = (k - amari) % loop_len + amari - 1
    #print(idx)
    print(A[idx])

if __name__ == '__main__':
    main()
0