結果

問題 No.2031 Colored Brackets
ユーザー wattaihei
提出日時 2022-08-05 23:24:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 486 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2024-09-15 21:00:36
合計ジャッジ時間 4,645 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod = 998244353

N = int(input())
S = list(input().rstrip())

dp = [0]*(N+1)
dp[0] = 1
r = 0
for s in S:
    t = 1 if s == "(" else -1
    ndp = [0]*(N+1)
    for i in range(N):
        if t == 1:
            ndp[i+1] += dp[i]
            ndp[i] += dp[i]
        else:
            if i-1 >= 0:
                ndp[i-1] += dp[i]
            if r - i > 0:
                ndp[i] += dp[i]
        ndp[i-1] %= mod
    r += t
    dp = ndp

print(dp[0])
0