結果

問題 No.2668 Trees on Graph Paper
ユーザー suisensuisen
提出日時 2023-12-28 03:33:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,011 ms / 3,000 ms
コード長 941 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,348 KB
最終ジャッジ日時 2024-02-11 22:15:46
合計ジャッジ時間 13,219 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 144 ms
75,348 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 37 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 39 ms
53,460 KB
testcase_13 AC 39 ms
53,460 KB
testcase_14 AC 631 ms
75,348 KB
testcase_15 AC 928 ms
75,348 KB
testcase_16 AC 500 ms
75,348 KB
testcase_17 AC 105 ms
75,348 KB
testcase_18 AC 882 ms
75,348 KB
testcase_19 AC 769 ms
75,348 KB
testcase_20 AC 830 ms
75,348 KB
testcase_21 AC 789 ms
75,348 KB
testcase_22 AC 809 ms
75,348 KB
testcase_23 AC 534 ms
75,348 KB
testcase_24 AC 1,005 ms
75,348 KB
testcase_25 AC 1,011 ms
75,348 KB
testcase_26 AC 1,008 ms
75,348 KB
testcase_27 AC 1,008 ms
75,348 KB
testcase_28 AC 37 ms
53,460 KB
testcase_29 AC 37 ms
53,460 KB
testcase_30 AC 37 ms
53,460 KB
testcase_31 AC 37 ms
53,460 KB
testcase_32 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())

ans = 1
# dp(_,f,g) <==> pd[2f+g]
pd = [1, 0, 0, 0]
for x in range(2 * N - 3):
    # pd: dp(x,*,*), dp: dp(x+1,*,*)
    dp = [0, 0, 0, 0]
    for f in (0, 1):
        # T: tofu, R: red ball, W: white ball

        # g=0 (RTRT...RT)
        val = pd[2 * f]
        ## put W
        dp[0b00] += val
        ## put R
        dp[0b11] += val

        # g=1 (RTRT...TR)
        val = pd[2 * f + 1]
        ## put W
        dp[0b01] += val
        ## put TR
        weight_red = 1 if f else x # if f==0 then vertex (x,_) has degree of 1
        dp[0b11] += val * weight_red
        ## put TW
        weight_white = weight_red * (x + 1) % M # vertex (x+1,_) has degree of 1
        dp[0b00] += val * weight_white

    for i in range(4):
        pd[i] = dp[i] % M

    if x % 2 == 0:
        # level x/2+1
        ans = ans * (pd[1] + pd[3]) % M

# level N
for x in range(1, 2 * N):
    ans = ans * x % M
print(ans)
0