結果

問題 No.1595 The Final Digit
ユーザー moharan627moharan627
提出日時 2021-07-12 20:47:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 8,664 KB
最終ジャッジ日時 2023-09-14 20:45:36
合計ジャッジ時間 1,819 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,644 KB
testcase_01 AC 18 ms
8,552 KB
testcase_02 AC 19 ms
8,552 KB
testcase_03 AC 19 ms
8,516 KB
testcase_04 AC 18 ms
8,656 KB
testcase_05 AC 18 ms
8,524 KB
testcase_06 AC 18 ms
8,560 KB
testcase_07 AC 19 ms
8,624 KB
testcase_08 AC 19 ms
8,560 KB
testcase_09 AC 19 ms
8,660 KB
testcase_10 AC 19 ms
8,664 KB
testcase_11 AC 19 ms
8,644 KB
testcase_12 AC 18 ms
8,628 KB
testcase_13 AC 19 ms
8,560 KB
testcase_14 AC 18 ms
8,544 KB
testcase_15 AC 18 ms
8,620 KB
testcase_16 AC 18 ms
8,644 KB
testcase_17 AC 19 ms
8,624 KB
testcase_18 AC 19 ms
8,552 KB
testcase_19 AC 19 ms
8,648 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-3)%PLen][2])
    return
solve()
#sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
0