結果

問題 No.44 DPなすごろく
ユーザー terrafarmterrafarm
提出日時 2020-12-14 08:54:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 881 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 11,864 KB
実行使用メモリ 11,976 KB
最終ジャッジ日時 2023-10-20 04:47:32
合計ジャッジ時間 2,297 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import logging
import sys
from inspect import currentframe

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

logging.basicConfig(level=logging.DEBUG)


def dbg(*args):
    id2names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    logging.debug(
        ", ".join(id2names.get(id(arg), "???") + " = " + repr(arg) for arg in args)
    )


def rec(n):
    if memo[n] != -1:
        return memo[n]
    if n == 0:
        memo[0] = 1
        return 1
    elif n == 1:
        memo[1] = 1
        return 1
    else:
        memo[n] = rec(n - 1) + rec(n - 2)
        return rec(n - 1) + rec(n - 2)


memo = [-1] * 61


def main():

    n = int(input())
    # dp = [0] * (n + 1)
    # dp[0] = 1
    # dp[1] = 1
    # for i in range(2, n + 1):
    #     dp[i] = dp[i - 1] + dp[i - 2]
    print(rec(n))
    # print(dp[n])


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