結果

問題 No.2031 Colored Brackets
ユーザー vwxyz
提出日時 2024-12-19 15:22:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 76,060 KB
最終ジャッジ日時 2024-12-19 15:22:32
合計ジャッジ時間 3,482 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
S=input()
mod=998244353
cnt=0
dp=[1]
for s in S:
    prev=dp
    prev_cnt=cnt
    cnt=prev_cnt+(s=="(")*2-1
    dp=[0]*(cnt+1)
    for c in range(prev_cnt+1):
        if s=="(":
            dp[c+1]+=prev[c]
            dp[c+1]%=mod
            dp[c]+=prev[c]
            dp[c]%=mod
        else:
            if c:
                dp[c-1]+=prev[c]
                dp[c-1]%=mod
            if c<cnt+1:
                dp[c]+=prev[c]
                dp[c]%=mod
ans=dp[0]
print(ans)
0