結果

問題 No.3099 Parentheses Decomposition
ユーザー Facade
提出日時 2025-04-11 22:05:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 620 ms / 2,000 ms
コード長 409 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 137,588 KB
最終ジャッジ日時 2025-04-11 22:05:19
合計ジャッジ時間 4,502 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
s=list(input())
mod=998244353
fact=[1]

for i in range(1,5*10**5+1):
    fact.append(fact[-1]*i)
    fact[-1]%=mod
def comb(a,b):
    return fact[a]*pow((fact[b]*fact[a-b])%mod,mod-2,mod)

if not ("".join(s[:n//2])=="("*(n//2) and "".join(s[n//2:])==")"*(n//2)):
    print(pow(2,n//2,mod))
else:
    ans=0
    for i in range(n//2+1):
        ans+=comb(n//2,i)**2
        ans%=mod
    print(ans)
0