結果

問題 No.3099 Parentheses Decomposition
ユーザー D M
提出日時 2025-04-18 12:14:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 72,112 KB
最終ジャッジ日時 2025-04-18 12:14:48
合計ジャッジ時間 3,351 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
n//=2
s=input()
mod=998244353
class cMod :
    def __init__(self, mod, size):
        fact = [1 for _ in range(size)]
        ifact = [1 for _ in range(size)]

        for i in range(1, size) :
            fact[i] = fact[i-1] * i % mod

        ifact[size-1] = pow(fact[size-1], mod-2, mod)

        for i in range(size-2, -1, -1):
            ifact[i] = ifact[i+1] * (i+1) % mod
        self.fact = fact
        self.ifact = ifact


    def nCk(self, n: int, k: int) -> int:
        if n < k or k < 0 : return 0
        return self.fact[n] * self.ifact[k] % mod * self.ifact[n-k]%mod
m=cMod(mod,6*10**5)
if s[1]=="(":
    print(m.nCk(2*n,n))
else:
    print(pow(2,n,mod))
0