結果

問題 No.1595 The Final Digit
ユーザー moharan627
提出日時 2021-07-12 20:47:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-02 03:36:08
合計ジャッジ時間 4,527 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = float('inf')
#10**20,2**63,float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
#from collections import defaultdict
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    P,Q,R,K = MI()
    from collections import defaultdict
    PLegflag = defaultdict(lambda:False)
    LegP = []
    P_1 = -1
    X = (P%10,Q%10,R%10)
    while(1):
        if(PLegflag[X]):
            P_1 = X
            break
        PLegflag[X] = True
        LegP.append(X)
        x3,x2,x1 = X
        X = (x2,x1,(x3+x2+x1)%10)

    LegLen = 0
    PLen = 0
    for x in LegP:
        if(x == P_1):
            PLen = len(LegP)-LegLen
            break
        else:
            LegLen += 1
    Leg = LegP[:LegLen]
    Period = LegP[LegLen:]
    #print(Leg, LegLen)
    #print(Period, PLen)
    if(K-3 <= LegLen-1):
        print(Leg[K-3][2])
    else:
        print(Period[(K-3)%PLen][2])
    return
solve()
#sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
0