結果

問題 No.3145 Astral Parentheses Sequence
ユーザー detteiuu
提出日時 2025-07-16 23:10:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 776 ms / 2,000 ms
コード長 386 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,840 KB
実行使用メモリ 76,624 KB
最終ジャッジ日時 2025-07-16 23:11:06
合計ジャッジ時間 14,951 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def func(n):
    if n in memo:
        return memo[n]
    if n <= 1:
        memo[n] = 1
        return memo[n]
    ans = 0
    for i in range(n):
        for j in range(i+1):
            ans += func(j)*func(i-j)%M*func(n-1-i)%M
            ans %= M
    memo[n] = ans
    return memo[n]

if N%3 != 0:
    exit(print(0))

memo = dict()
print(func(N//3))
0