結果

問題 No.1667 Forest
ユーザー hir355hir355
提出日時 2021-09-03 22:40:11
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 699 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 153,984 KB
最終ジャッジ日時 2024-05-09 05:37:53
合計ジャッジ時間 21,055 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 2,969 ms
150,352 KB
testcase_03 AC 89 ms
76,452 KB
testcase_04 TLE -
testcase_05 AC 1,724 ms
107,520 KB
testcase_06 AC 1,028 ms
90,412 KB
testcase_07 AC 627 ms
83,200 KB
testcase_08 AC 316 ms
78,472 KB
testcase_09 AC 216 ms
77,160 KB
testcase_10 AC 138 ms
76,544 KB
testcase_11 AC 74 ms
74,624 KB
testcase_12 AC 36 ms
52,096 KB
testcase_13 AC 34 ms
52,224 KB
testcase_14 AC 36 ms
52,352 KB
testcase_15 AC 36 ms
51,968 KB
testcase_16 AC 35 ms
51,968 KB
testcase_17 AC 35 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, MOD = map(int, input().split())
nCr = [[0] * (n + 1) for _ in range(n + 1)]
nCr[0][0] = 1
for i in range(n + 1):
    for j in range(n + 1):
        nCr[i][j] %= MOD
        if i < n:
            nCr[i + 1][j] += nCr[i][j]
            if j < n:
                nCr[i + 1][j + 1] += nCr[i][j]
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
    for j in range(n):
        dp[i][j] %= MOD
        for k in range(1, n + 1 - i):
            if k == 1:
                dp[i + k][j + 1] += dp[i][j] * nCr[n - i - 1][k - 1]
            else:
                dp[i + k][j + 1] += dp[i][j] * nCr[n - i - 1][k - 1] * pow(k, k - 2, MOD)
for x in dp[n][::-1][:-1]:
    print(x % MOD)
0