結果

問題 No.2031 Colored Brackets
ユーザー lloyzlloyz
提出日時 2023-09-25 21:58:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 77,864 KB
最終ジャッジ日時 2023-09-25 21:58:34
合計ジャッジ時間 6,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,296 KB
testcase_01 AC 73 ms
71,416 KB
testcase_02 AC 76 ms
71,148 KB
testcase_03 AC 81 ms
75,056 KB
testcase_04 AC 126 ms
77,300 KB
testcase_05 AC 105 ms
77,216 KB
testcase_06 AC 114 ms
77,468 KB
testcase_07 AC 77 ms
75,180 KB
testcase_08 AC 144 ms
77,456 KB
testcase_09 AC 152 ms
77,492 KB
testcase_10 AC 170 ms
77,420 KB
testcase_11 AC 152 ms
77,200 KB
testcase_12 AC 173 ms
77,760 KB
testcase_13 AC 125 ms
77,448 KB
testcase_14 AC 171 ms
77,548 KB
testcase_15 AC 172 ms
77,520 KB
testcase_16 AC 183 ms
77,408 KB
testcase_17 AC 172 ms
77,800 KB
testcase_18 AC 148 ms
77,660 KB
testcase_19 AC 142 ms
77,416 KB
testcase_20 AC 124 ms
77,760 KB
testcase_21 AC 131 ms
77,864 KB
testcase_22 AC 129 ms
77,300 KB
testcase_23 AC 155 ms
77,780 KB
testcase_24 AC 74 ms
71,120 KB
testcase_25 AC 74 ms
71,292 KB
testcase_26 AC 74 ms
71,568 KB
testcase_27 AC 80 ms
75,272 KB
testcase_28 AC 73 ms
71,552 KB
testcase_29 AC 77 ms
71,500 KB
testcase_30 AC 76 ms
71,436 KB
testcase_31 AC 90 ms
76,244 KB
testcase_32 AC 76 ms
71,328 KB
testcase_33 AC 88 ms
76,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = list(input())
mod = 998244353

Open = [0 for _ in range(n)]
Close = [0 for _ in range(n)]
for i in range(n):
    if S[i] == '(':
        Open[i] += 1
    else:
        Close[i] += 1
    Open[i] += Open[i - 1]
    Close[i] += Close[i - 1]

DP = [0 for _ in range(n + 1)]
DP[0] = 1
for i in range(n):
    NDP = [0 for _ in range(n + 1)]
    dif = Open[i] - Close[i]
    if S[i] == '(':
        for j in range(i + 1):
            NDP[j + 1] += DP[j]
            NDP[j + 1] %= mod
            NDP[j] += DP[j]
            NDP[j] %= mod
    else:
        for j in range(i + 1):
            if j > 0:
                NDP[j - 1] += DP[j]
                NDP[j - 1] %= mod
            if dif - j >= 0:
                NDP[j] += DP[j]
                NDP[j] %= mod
    DP = NDP
print(DP[0])
0