結果

問題 No.1595 The Final Digit
ユーザー moharan627moharan627
提出日時 2021-07-12 20:46:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,194 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2023-09-14 20:45:25
合計ジャッジ時間 2,158 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,608 KB
testcase_01 AC 19 ms
8,644 KB
testcase_02 RE -
testcase_03 AC 19 ms
8,700 KB
testcase_04 AC 19 ms
8,692 KB
testcase_05 AC 19 ms
8,508 KB
testcase_06 AC 19 ms
8,576 KB
testcase_07 RE -
testcase_08 AC 20 ms
8,572 KB
testcase_09 AC 19 ms
8,528 KB
testcase_10 AC 19 ms
8,660 KB
testcase_11 AC 20 ms
8,612 KB
testcase_12 AC 19 ms
8,512 KB
testcase_13 AC 19 ms
8,592 KB
testcase_14 AC 19 ms
8,564 KB
testcase_15 AC 19 ms
8,612 KB
testcase_16 AC 19 ms
8,624 KB
testcase_17 AC 19 ms
8,608 KB
testcase_18 AC 19 ms
8,664 KB
testcase_19 AC 19 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

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%PLen-3][2])
    return
solve()
#sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
0