結果

問題 No.1595 The Final Digit
ユーザー HAPPAHAPPA
提出日時 2021-07-11 13:48:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2023-09-14 20:09:20
合計ジャッジ時間 1,447 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,848 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 16 ms
7,772 KB
testcase_03 AC 15 ms
7,856 KB
testcase_04 AC 15 ms
7,904 KB
testcase_05 AC 15 ms
7,788 KB
testcase_06 AC 15 ms
7,868 KB
testcase_07 AC 16 ms
7,824 KB
testcase_08 AC 15 ms
7,972 KB
testcase_09 AC 15 ms
7,824 KB
testcase_10 AC 16 ms
7,864 KB
testcase_11 AC 16 ms
7,896 KB
testcase_12 AC 15 ms
7,888 KB
testcase_13 AC 16 ms
7,872 KB
testcase_14 AC 15 ms
7,956 KB
testcase_15 AC 15 ms
7,836 KB
testcase_16 AC 15 ms
7,812 KB
testcase_17 AC 16 ms
7,952 KB
testcase_18 AC 15 ms
7,872 KB
testcase_19 AC 16 ms
7,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
MOD = 10 ** 9 + 7


def solve():
    p, q, r, k = map(int, input().split())
    p, q, r = map(lambda x: x % 10, [p, q, r])
    MAX = 1001
    dp = [0] * MAX
    dp[0], dp[1], dp[2] = p, q, r
    cycle = 0
    for i in range(3, MAX):
        cycle += 1
        dp[i] = (dp[i - 3] + dp[i - 2] + dp[i - 1]) % 10
        if (dp[0], dp[1], dp[2]) == (dp[i - 2], dp[i - 1], dp[i]):
            break
    k %= cycle
    print(dp[k - 1])


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