結果

問題 No.3099 Parentheses Decomposition
ユーザー titia
提出日時 2025-04-11 21:35:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 82,608 KB
実行使用メモリ 219,204 KB
最終ジャッジ日時 2025-04-11 21:35:15
合計ジャッジ時間 5,194 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=998244353

FACT=[1]
for i in range(1,10**6+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(10**6,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod
    else:
        return 0


N=int(input())
S=input().strip()

if S[1]=="(":
    ANS=0

    x=N//2

    for i in range(x+1):
        ANS=(ANS+Combi(x,i)*Combi(x,i))%mod

    print(ANS)

else:
    x=N//2

    print(pow(2,x,mod))
0