結果

問題 No.1595 The Final Digit
ユーザー syunsukesyunsuke
提出日時 2021-07-10 17:46:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 76,304 KB
最終ジャッジ日時 2023-09-14 19:44:07
合計ジャッジ時間 3,225 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,640 KB
testcase_01 AC 86 ms
71,724 KB
testcase_02 AC 87 ms
71,752 KB
testcase_03 AC 88 ms
71,716 KB
testcase_04 AC 87 ms
71,332 KB
testcase_05 AC 86 ms
71,328 KB
testcase_06 AC 87 ms
71,776 KB
testcase_07 AC 90 ms
71,604 KB
testcase_08 AC 86 ms
71,604 KB
testcase_09 AC 87 ms
71,452 KB
testcase_10 AC 87 ms
71,376 KB
testcase_11 AC 88 ms
71,656 KB
testcase_12 AC 95 ms
76,140 KB
testcase_13 AC 90 ms
71,584 KB
testcase_14 AC 95 ms
76,304 KB
testcase_15 AC 93 ms
76,148 KB
testcase_16 AC 88 ms
71,656 KB
testcase_17 AC 88 ms
71,528 KB
testcase_18 AC 92 ms
71,712 KB
testcase_19 AC 90 ms
71,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

A,B,C,K = map(int,input().split())

D = {}
A %= 10
B %= 10
C %= 10


from collections import deque
Q = [A,B,C]
Q = deque(Q)

for i in range(4,K+1):
    if i == K:
        print(sum(Q)%10)
        exit()
    elif (Q[0],Q[1],Q[2]) not in D:
        D[(Q[0],Q[1],Q[2])] = i
        S = sum(Q)
        Q.append(S%10)
        a = Q.popleft()
        #print(Q)
    else:
        I = i
        #print(D[(Q[0],Q[1],Q[2])],I)
        break
#print(Q)
#print(D)

K -= D[(Q[0],Q[1],Q[2])]
K %= (I-D[(Q[0],Q[1],Q[2])])
#print(K)
for i in range(K+1):
    S = sum(Q)
    Q.append(S%10)
    a = Q.popleft()
    #print(i,Q)
print(S%10)
0