結果

問題 No.1595 The Final Digit
ユーザー kept1994kept1994
提出日時 2021-08-27 02:02:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 2,008 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 65,152 KB
最終ジャッジ日時 2024-04-29 19:37:07
合計ジャッジ時間 2,197 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
65,024 KB
testcase_01 AC 56 ms
64,896 KB
testcase_02 AC 56 ms
65,024 KB
testcase_03 AC 55 ms
64,896 KB
testcase_04 AC 56 ms
64,768 KB
testcase_05 AC 56 ms
65,024 KB
testcase_06 AC 56 ms
65,152 KB
testcase_07 AC 55 ms
65,024 KB
testcase_08 AC 55 ms
64,768 KB
testcase_09 AC 55 ms
64,768 KB
testcase_10 AC 54 ms
64,768 KB
testcase_11 AC 55 ms
64,896 KB
testcase_12 AC 53 ms
64,768 KB
testcase_13 AC 54 ms
64,768 KB
testcase_14 AC 57 ms
65,152 KB
testcase_15 AC 54 ms
65,152 KB
testcase_16 AC 54 ms
64,768 KB
testcase_17 AC 55 ms
65,152 KB
testcase_18 AC 55 ms
64,768 KB
testcase_19 AC 55 ms
64,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys


def main():
    def converter(i):
        S = str(i)
        if len(S) == 1:
            return [0, 0, i]
        elif len(S) == 2:
            return [0, int(S[0]), int(S[1])]
        else:
            return [int(S[0]), int(S[1]), int(S[2])]
    class Doubling:
        def __init__(self, stateKind: int, maxDoublingTimes: int):
            self.dv = []                                # 数列(状態)のダブリングテーブル。dv[k][s] := 状態sを2^k回実行したらあとの状態
            self.sum = []                               # 和のダブリングテーブル
            self.stateKind = stateKind                  # 状態の種類数s
            self.maxDoublingTimes = maxDoublingTimes    # 実行回数kの範囲の定義(2^0 ≦ k ≦ 2^maxDoublingTimes)
            self._initTable()
            self._createTable()
        
        # 初期化処理
        def _initTable(self):
            ll = []
            for i in range(1000):
                l = converter(i)
                ll.append(l[1] * 100 + l[2] * 10 + sum(l) % 10)
            self.dv.append(ll)
        
        # ダブリング実施
        def _createTable(self):
            for i in range(1, self.maxDoublingTimes):
                l = []
                for j in range(self.stateKind):
                    l.append(self.dv[i - 1][self.dv[i - 1][j]])
                self.dv.append(l)
            
        def getState(self, doubingTimes: int, startState: int):
            a = []
            for i in range(self.maxDoublingTimes):
                if doubingTimes >> i & 1:
                    a.append(i)
            now = startState
            for i in a:
                now = self.dv[i][now]
            return now

    p, q, r, K = map(int, input().split())
    num = (p % 10) * 100 + (q % 10) * 10 + (r % 10)
    d = Doubling(1000, 60)
    print(str(d.getState(startState=num, doubingTimes=(K - 3)))[-1])


    return

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