結果

問題 No.554 recurrence formula
ユーザー magurogumamaguroguma
提出日時 2017-09-24 00:58:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 520 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 18,012 KB
最終ジャッジ日時 2023-08-09 00:31:02
合計ジャッジ時間 15,035 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
18,012 KB
testcase_01 AC 19 ms
8,840 KB
testcase_02 AC 18 ms
8,768 KB
testcase_03 AC 18 ms
8,772 KB
testcase_04 AC 17 ms
8,772 KB
testcase_05 AC 18 ms
8,748 KB
testcase_06 AC 18 ms
8,708 KB
testcase_07 AC 17 ms
8,756 KB
testcase_08 AC 18 ms
8,696 KB
testcase_09 AC 17 ms
8,712 KB
testcase_10 AC 78 ms
8,844 KB
testcase_11 AC 598 ms
8,952 KB
testcase_12 AC 441 ms
8,700 KB
testcase_13 AC 1,845 ms
9,036 KB
testcase_14 AC 602 ms
9,116 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 AC 1,277 ms
9,024 KB
testcase_18 AC 1,043 ms
8,980 KB
testcase_19 TLE -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

import sys

N = int(input())
M = 10**9 + 7

dp = [0] * (10**5 + 1)
def recurrence(n):
    if n==1:
        dp[n] = 1
    elif n==2:
        dp[n] = 2
    elif n==3:
        dp[n] = 6
    elif n==4:
        dp[n] = 28
    else:
        #dp[n] = (n * (dp[n-2]//(n-2)%M + dp[n-1]%M)) % M
        for i in range(n-1, 0, -2):
            dp[n] += dp[i] % M
        dp[n] *= n
        dp[n] %= M
    return dp[n]

sys.setrecursionlimit(10**5+1)

for i in range(1, N+1):
    recurrence(i)

print(dp[N])
0